遍历集合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());
相关推荐
WiChP6 小时前
【V0.1B5】从零开始的2D游戏引擎开发之路
java·服务器·数据库
cch89186 小时前
汇编与Java:底层与高层的编程对决
java·开发语言·汇编
荒川之神7 小时前
拉链表概念与基本设计
java·开发语言·数据库
cch89187 小时前
汇编与Go:底层到高层的编程差异
java·汇编·golang
chushiyunen7 小时前
python中的@Property和@Setter
java·开发语言·python
禾小西7 小时前
Java中使用正则表达式核心解析
java·python·正则表达式
yoyo_zzm7 小时前
JAVA (Springboot) i18n国际化语言配置
java·spring boot·python
APIshop7 小时前
Java获取京东商品详情接口(item_get)实战指南
java·linux·数据库
Mr.Entropy7 小时前
springboot2.x集成Flyway
java