0.根据集合的对象或属性 正序排序
0.1根据属性
List<Goods> collect = goodsList.stream().sorted(Comparator.comparing(Goods::getAmunt)).collect(Collectors.toList());
0.2根据对象本身,适应于(List<Integer> 或 List<String>)
List<String> collect = list.stream().sorted(Comparator.comparing(Function.identity())).collect(Collectors.toList());
1.根据集合的对象的属性(Integer)进行排序
1.1正序
List<Goods> collect = goodsList.stream()
.sorted((x,y) -> Integer.compare(x.getAmunt(),y.getAmunt()))
.collect(Collectors.toList());
1.2逆序
List<Goods> collect = goodsList.stream()
.sorted((x,y) -> Integer.compare(y.getAmunt(),x.getAmunt()))
.collect(Collectors.toList());
2.根据集合的对象的属性(String)进行排序
2.1正序
List<Goods> collect = goodsList.stream()
.sorted((x,y) -> x.getName().compareTo(y.getName()))
.collect(Collectors.toList());
2.2 逆序
List<Goods> collect = goodsList.stream()
.sorted((x,y) -> y.getName().compareto(x.getName()))
.collect(Collectors.toList());