【工具类】JAVA8-用lamda表达式和增强版Comparator进行排序

1、单条件升序:

list.sort(Comparator.comparing(User::getId);

2、降序:

list.sort(Comparator.comparing(User::getId).reversed());

3、多条件升序排序:

list.sort(Comparator.comparing(User::getId).thenComparing(User::getName));

 

 

 

转载:http://blog.csdn.net/gao1440156051/article/details/71126194

posted @ 2018-11-28 08:46  青取之于蓝  阅读(2121)  评论(0编辑  收藏  举报