List<实体>排序
正序
list.stream()
.sorted(Comparator.comparing(Entity::getId))
.collect(Collectors.toList());
倒序
list.stream()
.sorted(Comparator.comparing(Entity::getId).reversed())
.collect(Collectors.toList());

本文介绍了一种使用Java Stream API对List中的实体对象进行排序的方法。包括按实体ID正序及倒序排列的具体实现方式。

3389

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



