I have the following classes.
Class A {
List<B> b
//getters and setters
}
CLass B {
List<C> c
//getters and setters
}
Class C {
List<D> d
//getters and setter
}
Class D {}
What i want to do is remove list d
if a specific search term is not in the list. I have tried to do it but no luck. I think it removes but the reference is not saved.
a.stream()
.flatMap(a-> a.getB().stream())
.flatMap(b-> b.getC().stream())
.map(c-> c.getD())
.collect(Collectors.toList())
.removeIf(list -> {
boolean toBeRemoved = true;
boolean containsMatch = list.stream().anyMatch(w-> {return w.getId().equalsIgnoreCase(searchTerm);});
if(containsMatch) {
toBeRemoved = false;
}
return toBeRemoved;
});
Can someone help me?