1, 对整数列表排序(升序)
Listlist = Arrays.asList(1, 4, 2, 6, 2, 8); list.sort(Comparator.naturalOrder());
2, 对整数列表排序(降序)
Listlist = Arrays.asList(1, 4, 2, 6, 2, 8); list.sort(Comparator.reverseOrder());
3,按照List中对象的id属性升序
list.sort(Comparator.comparing(User::getId))
4, 按照List中对象的id属性降序
list.sort(Comparator.comparing(User::getId).reversed());
5,多个条件升序
list.sort(Comparator.comparing(User::getId).thenComparing(User::getDeId));
6,// id升序,deId降序
list.sort(Comparator.comparing(User::getId).reversed().thenComparing(User::getDeId));
7,Collection升序排序
Collections.sort(user, new Comparator(){ public int compare(User p1, User p2) { return Integer.parseInt(p1.getUserCode()) - Integer.parseInt(p2.getUserCode()); } });
就问总结的到不到位,点赞留言啦