排序分顺逆
顺
List<对象> list = data.stream().sorted(Comparator.comparing(对象::get属性))
.collect(Collectors.toList());
逆
List<对象> list1 = data.stream().sorted(Comparator.comparing(对象::get属性).reversed())
.collect(Collectors.toList());
本文介绍如何使用Java Stream API进行列表排序,包括正序和逆序两种方式,并提供了具体的代码示例。
排序分顺逆
顺
List<对象> list = data.stream().sorted(Comparator.comparing(对象::get属性))
.collect(Collectors.toList());
逆
List<对象> list1 = data.stream().sorted(Comparator.comparing(对象::get属性).reversed())
.collect(Collectors.toList());
1441
758
1136

被折叠的 条评论
为什么被折叠?
