java工具:Java 8 Stream实现List集合排序

0 阅读1分钟

在这里插入图片描述 @[toc]

一、介绍

该代码使用 Java 8 Stream 的 sorted() 方法和 Comparator.comparing() 对 Repeater 对象列表按照 siteId 字段进行升序排序,并收集为新的 List 集合。

二、代码

List<Repeater> repeaterList = rptList.stream().sorted(Comparator.comparing(Repeater::getSiteId)).collect(Collectors.toList());	

image.png

重要信息

image.png

image.png

image.png