遍历集合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());
相关推荐
无尽冬.5 分钟前
个人八股之三层架构
java·经验分享·后端·架构·异世界
贫民窟的勇敢爷们10 分钟前
SpringBoot多环境配置全解+配置优先级管控
java·spring boot·后端
tellmewhoisi16 分钟前
单独抽取用户服务(请求不通):feign添加拦截器(添加token)
java·开发语言
YL2004042628 分钟前
035LRU缓存
java·leetcode·缓存
不像程序员的程序媛44 分钟前
mysql 0000-00-00 00:00:00零日期问题
java·mysql
霸道流氓气质1 小时前
Spring @Scheduled 单线程陷阱:当设备重连阻塞了整个定时任务体系
java·spring boot·spring
DFT计算杂谈1 小时前
AMSET 设置多核并行计算
java·前端·css·html·css3
Gerardisite1 小时前
CRM、ERP、OA 如何连接企业微信?QiWe 提供标准化解决方案
java·python·机器人·自动化·企业微信
城管不管1 小时前
Maven Helper
java·macos·intellij-idea
ch.ju1 小时前
Java程序设计(第3版)第三章——数组的动态获取
java·开发语言