Consider a Parent
class with the attributes attrib1
, attrib2
and List
child with its corresponding getters and s
What you need is a Stream
if you want to receive all children. The following expression might do the trick:
parents.stream().flatMap(e -> e.getChildren().stream()).filter(c -> c.getAttrib1() > 10)
This should return all children of all parents in the list where the get attribute value is greater than 10.
If you want to update the parents list by removing all child elements that fail a condition, you can do the following:
parents.forEach(p -> p.getChildren().removeIf(c -> c.getAttrib1() > 10));
This doesn't create a new list. Instead it updates the parents
list itself.