Java 8 lambda filtering based on condition as well as order

后端 未结 4 729
清酒与你
清酒与你 2021-01-01 13:36

I was trying to filter a list based on multiple conditions, sorting.

class Student{
        private int Age;
        private String className;
        privat         


        
4条回答
  •  萌比男神i
    2021-01-01 14:12

    Or without streams:

    Map map = new HashMap<>();
    students.forEach(x -> map.merge(x.getName(), x, (oldV, newV) -> oldV.getAge() > newV.getAge() ? oldV : newV));
    Collection max = map.values();
    

提交回复
热议问题