遍历集合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());
相关推荐
少年的范儿8 小时前
IntelliJ IDEA 配置 JDK 21 与 Maven 教程(Windows):开发环境配置与验证
java·jdk·maven·intellij idea
RuoyiOffice8 小时前
SpringBoot3 + openGauss:RuoYi Office 登录、流程发布与用印填报适配实战
java·数据库·spring boot·opengauss·信创
Dwzun8 小时前
基于SpringBoot3+Vue3的油莎豆种植管理系统
java·前端·vue.js·spring boot·后端·python·计算机网络
学长毕设17 小时前
基于SpringBoot的实验室资产管理系统
java·spring boot·后端
zzu123zsw18 小时前
从臃肿的模板调用到声明式契约:深入 UniHttp 动态代理与多渠道生命周期扩展
java·spring boot·microsoft·unihttp
源码集结号19 小时前
云诊所门诊系统源码,基于SpringBoot+Vue.js架构,支持多租户设计与Docker容器化部署
java·spring boot·源码·医院信息系统·门诊系统·诊所系统
论文复现现场19 小时前
WRF、FEA 能用 L40S 加速吗?求解器检查、断点恢复与长期运行
java·数据库·算法·wrf·有限元分析·gpu计算·断点续算
啃瓜子的松鼠20 小时前
泛微OAe9-后端二开异步调用
java
秋天的怀念_David21 小时前
第二十一夜 · 数字黑洞与西西弗斯的惩罚
java·程序人生·算法
外收内放21 小时前
Python基础语法练习题(73)
java·前端·python