Collections.sort() Comparable对象
1 | public class User implements Comparable<User> { |
排序
1 | Collections.sort(users); |
Collections.sort() 传入Comparator比较器
1 | Collections.sort(users, new Comparator<User>() { |
List接口的sort
1 | users.sort(Comparator.comparing(User::getCreatedOn)); |
Stream接口的sorted [Java8]
1 | List<User> sortedUsers = users.stream() |