Dear community, I have a problem in how to use streams, I have 3 classes:
public Class A{
String string1A;
String string2A;
List<B> listB;
.
.
.
}
public Class B{
String string1B;
String string2B;
.
.
.
}
public Class C{
String string1A;
String string2A;
String string1B;
String string2B;
.
.
.
}
Then I have a method that returns a List of C with all the data coming from a database, and I need to create a List A that has all the data grouped, as the grouping value is the String1A, what I know. it happened was this:
List<A> listaA = new ArrayList<A>();
Set<String> listString1A = listaC.stream().map(x->x.getString1A()).distinct().collect(Collectors.toSet());
for(String stringFilter1A: listString1A){
A a = listaC.stream().filter(x->getString1A().equals(stringFilter1A)).map(x-> new A(x.getString1A(),x.getString2A)).findFirst().get();
List<B> listaB = listaC.stream().filter(x->getString1A().equals(stringFilter1A)).map(x-> new B(...)).collect(Collectors.toList());
a.setListB(listaB);
listaA.add(a);
}
Is there a way to do this query using only streams or trying to delete the for?