遍历集合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());
相关推荐
文丑颜不良啊15 分钟前
LeetCode3401~3420题目解析
java·leetcode
文丑颜不良啊2 小时前
LeetCode3421~3440题目解析
java·leetcode
code2cat2 小时前
【随笔】Java客户端选了HTTP/3,怎样知道请求实际走了哪个版本
java·开发语言·http
码云社区4 小时前
Java在线租房系统源码:VR看房素材、房源图片与内容维护方案
java·vue.js·vr·租房小程序·在线租房·看房租房
码云社区4 小时前
Spring Boot智慧物业系统源码:合同到期提醒、续签资料与资产协作
java·spring boot·后端·物业管理·物业系统·智慧物业
AI开源软件4 小时前
Vue3+SpringBoot3 业务配置统一管理:接管、保存与回退怎样保留有效值
java·前端·vue.js·spring boot·vue·ruoyi office
陈如水5 小时前
Spring AI Alibaba 在多 Agent 场景下的实践
java·人工智能·spring
吃我一窝jio5 小时前
Docker+Jenkins+K8s全流程部署
java·开发语言·笔记·python
Resean02238 小时前
Spring 源码分析(六)循环依赖与三级缓存
java·spring·缓存
在爪洼山玩泥巴9 小时前
fastjson2 JSONPath 取不存在路径,为什么会抛 “not support”?
java·开发语言·jsonpath·fastjson