遍历集合list工具

文章目录

1.遍历集合list,返回第一个匹配的对象/不匹配返回null:

java 复制代码
XptSiteModel xptSite = xptSiteModleTemp.stream().filter(item -> item.getSiteID() == rpt.getSiteId()).findFirst().orElse(null);

2.集合list排序

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

3.遍历list对象,返回匹配的集合

java 复制代码
List<RepBaseInfo> tempRtpList = site.get_xptRptList().stream().filter(item -> item.getSystemType() != Utility.EnumSystemType.Unknown.getValue() && item.repeaterNetType == 04).toList();

4.从 dbRepeaters 列表中筛选出所有 repeaterId 在 repeaterIds 数组中的 Repeater 对象,并将这些对象收集到一个新的列表 filteredRepeaters 中

java 复制代码
List<Repeater> filteredRepeaters = dbRepeaters.stream()
	.filter(repeater -> Arrays.stream(repeaterIds).anyMatch(id -> id == repeater.getRepeaterId()))
	.collect(Collectors.toList());
相关推荐
IKUN家族1 小时前
Spring IoC&DI
java·spring·rpc
山荷枝3 小时前
03-框架--Spring
java·后端·spring
ChaHae-In3 小时前
SpringBoot统一功能处理
java·spring boot·后端
coder!mq3 小时前
说几个常见的语法糖?
java·开发语言·算法
gugucoding4 小时前
38. 【Java】Stream API(下):高级操作与性能
java·开发语言
心平气和量大福大4 小时前
android-实例-蒲公英-更新与安装-5-签名与生成APK
android·java·开发语言
952365 小时前
Spring-cloud配置中心
java·spring·spring cloud·微服务
ydd1001005 小时前
寻找两个正序数组的中位数 Java 题解,二分分割详解
java·开发语言
真上帝的左手6 小时前
10. 软件设计&架构-Spring Security 7 整合CAS SSO 单点登录
java·spring·架构·sso
Zane19946 小时前
单例线程安全、生产者消费者、死锁:并发面试三连问串讲
java·后端