I have to get the list of objects containing the max value. The comparator max in Java 8 returns only one object.
To do this I had to stream twice the list:
OptionalInt max = students.stream()
.mapToInt(student -> student.getAssignedProjects().size())
.max();
return this.students.stream()
.filter(student -> student.getAssignedProjects().size() == max.getAsInt())
.collect(Collectors.toSet());
This solution works. I think there is a better way to solve this but I ca not figure it out.