I've a school list which contains class, class list which also contains student and student are also another list. I want to apply two nested filter which first will check that if any class have a empty student list and second filter is for checking that if school has any empty class list and finally it should return the list but I just can't apply two filters as nested, I keep getting syntax error. I'm a bit new to stream api.
result = result.stream()
.filter(school -> school.getSchoolClassList().stream()
.filter(schoolClass-> schoolClass.getStudentList().stream()
.anyMatch(schoolClass-> schoolClass.getStudentList().size() > 0))
.anyMatch(school -> school.getSchoolClassList().size() > 0))
.collect(Collectors.toList());
You might want to add the resulting Syntax error. However, as I see at first is, that you are using
class
as an identifier, when it is actually a reserved keyword in Java programming language. Consider renaming the identifiers to something alikeschoolClass
.