Java 8 中的 Streams API 学习

xu.wang

发布于 2018.08.06 16:51 阅读 2262 评论 0

1、 List 排序

根据创建时间从小到大排序。

List<Record> recordList = db.getData();

recordList = 
recordList.stream()
.sorted(
Comparator.comparing
(
MpUserBookContent::getMubcCreateDate
)
).collect(Collectors.toList());

根据创建时间从大到小排序。

recordList =

recordList.stream().sorted

(

Comparator.comparing

(

MpUserBookContent::getMubcCreateDate

).reversed()

).collect(Collectors.toList());