java Collections.sort排序处理
List<User> list = new ArrayList<>(); list.add(new User(15, "小明")); list.add(new User(18, "小红")); list.add(new User(11, "小绿")); //匿名实现Comparator接口进行排序 Collections.sort(list, new Comparator<User>() { @Override public int compare(User o1, User o2) { return o1.getAge().compareTo(o2.getAge()); } }); //lambda表达式 Collections.sort(list,(User o1, User o2)->{ return o1.getAge().compareTo(o2.getAge()); }); list.forEach(System.out::println);