//循环两个列表通过ENDTIME与TIME相等将profitOfferRespList列表的Value放入profitRespList的CountPrice。以profitRespList为主表最后返回的事profitRespList
for (AggregatorDeviceDateProfitResp pro : profitRespList){
profitOfferRespList.stream().filter(s->s.getTime().equals(pro.getEndTime())).forEach(s->pro.setCountPrice(s.getValue()));
}
//如果对性能要求高可以将 副List转换成Map的形式这样可以减少副List的循环
Map<String, List> map = profitOfferRespList.stream().collect(groupingBy(DataResp::getTime));
for (AggregatorDeviceDateProfitResp pro : profitRespList){
List dataResps = map.get(pro.getEndTime());
if(CollectionUtils.isNotEmpty(dataResps)){
pro.setCountPrice(dataResps.get(0).getValue());
}
}
JAVA8循环两个List表
最新推荐文章于 2024-08-22 02:19:05 发布
本文介绍了一种通过遍历和过滤两个列表的方法,实现将一个列表中的值映射到另一个列表中对应项的过程,并提出使用Map来提高性能的优化方案。
1万+

被折叠的 条评论
为什么被折叠?



