I was trying to filter a list based on multiple conditions, sorting.
class Student{ private int Age; private String className; privat
Just to mix and merge the other solutions, you could alternatively do :
Map nameToStudentMap = new HashMap<>(); Set finalListOfStudents = students.stream() .map(x -> nameToStudentMap.merge(x.getName(), x, (a, b) -> a.getAge() > b.getAge() ? a : b)) .collect(Collectors.toSet());