遍历集合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());
相关推荐
YangYang9YangYan4 小时前
2026 校招审计风控岗位 JD 拆解,工具、专业能力与面试考点
java·大数据·人工智能·数据分析
wuminyu9 小时前
Kafka中sendfile与mmap实现机制解析
java·linux·c语言·jvm·c++
考虑考虑10 小时前
Java实现hmacsha256加密算法
java·后端·java ee
captain37610 小时前
▲网络原理(2)-TCP
java·服务器·网络·tcp/ip·java-ee
MetaLite11 小时前
SpringBoot接口分层规范-外网网关内部服务与参数边界
java·数据库·spring boot
Co_Hui11 小时前
Java 线程状态
java
土司大王11 小时前
LeetCode hot100——35.搜索插入位置:Java 二分模板、左闭右开区间与插入点分析
java·算法·leetcode
土司大王12 小时前
LeetCode hot100——34.在排序数组中查找元素的第一个和最后一个位置:Java 二分模板、边界分析
java·算法·leetcode
金金计较.12 小时前
Go语言-3
java·开发语言·golang
Wang's Blog13 小时前
Java框架快速入门: Spring Security+OAuth2之元注解简化权限表达式
java·数据库·spring