public static void main(String[] args) {
List<String> list = Arrays.asList("2", "3", "4", "2", "8", "5", "1");
Collections.sort(list);
Collections.reverse(list);
list.forEach(System.out::println);
List<User> userList = new ArrayList<User>();
userList.add(new User("张三", 20));
userList.add(new User("李四", 22));
userList.add(new User("王五", 10));
Collections.sort(userList, new Comparator<User>() {
@Override
public int compare(User user, User t1) {
return t1.getAge() - user.getAge();
}
});
userList.forEach(System.out::println);
}
@Test
public void test7(){
ArrayList<User> users = new ArrayList<>();
users.add(new User("Tom", 10));
users.add(new User("Tom2", 20));
users.add(new User("Tom3", 30));
users.add(new User("Tom4", 40));
users.sort(Comparator.comparing(User::getAge).reversed());
System.out.println(JSONArray.toJSONString(users));
}