遍历集合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());
相关推荐
超级大只老咪10 小时前
数组相邻元素比较的循环条件(Java竞赛考点)
java
小浣熊熊熊熊熊熊熊丶10 小时前
《Effective Java》第25条:限制源文件为单个顶级类
java·开发语言·effective java
毕设源码-钟学长10 小时前
【开题答辩全过程】以 公交管理系统为例,包含答辩的问题和答案
java·eclipse
啃火龙果的兔子10 小时前
JDK 安装配置
java·开发语言
星哥说事10 小时前
应用程序监控:Java 与 Web 应用的实践
java·开发语言
派大鑫wink11 小时前
【JAVA学习日志】SpringBoot 参数配置:从基础到实战,解锁灵活配置新姿势
java·spring boot·后端
xUxIAOrUIII11 小时前
【Spring Boot】控制器Controller方法
java·spring boot·后端
Dolphin_Home11 小时前
从理论到实战:图结构在仓库关联业务中的落地(小白→中级,附完整代码)
java·spring boot·后端·spring cloud·database·广度优先·图搜索算法
醇氧11 小时前
org.jetbrains.annotations的@Nullable 学习
java·开发语言·学习·intellij-idea
Java&Develop11 小时前
Aes加密 GCM java
java·开发语言·python