Consider a Parent class with the attributes attrib1, attrib2 and List<Child> child with its corresponding getters and setters.
The Child is another class with five attributes attrib1-attrib5 with its corresponding getters and setters.
Now I created a List<Parent> parent. Then I want to filter out a List<Parent> with following condition:- Child.Attrib1 > 10;
So I created the following query by Java 8 streams.
parent.stream().filter(e -> e.getChild().stream().anyMatch(c -> c.getAttrib1() > 10));
But the problem is I will get all the child in each Parent object. Here I want to get only those child object in List<Child> that obeys the given condition.
How should I remove all the child objects in List that doesn't obeys the condition and get the new List.