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

image

@

一、介绍

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

二、代码

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

image

重要信息

image
image
image

posted @ 2026-02-27 19:44  刘大猫26  阅读(0)  评论(0)    收藏  举报