I have a class
class TestA {
private List<A> listA;
//Getters and Setters
}
and another class
class A{
int id;
}
Now if want to collect all A into a List like below code
List<TestA> someList ; //Containing TestA
List<A> completeList = new LinkedList<A>();
for(TestA test:someList) {
if(test.getListA() != null) {
completeList.addAll(listA);
}
}
How can I get completeList using Lambda + Stream . Thanks for help in advance.
It should look something like this...
someList.stream()
.map(TestA::getListA)
.filter(testA -> testA != null && !testA.isEmpty())
.flatMap(List::stream)
.collect(Collectors.toList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With