stream同时循环两个List并将其中一个list中的数据赋值到另一个list中
stream同时循环两个List并将其中一个list中的数据赋值到另一个list中
·
源码如下
//获取otherList数据
List<SampleTestProgressDTO> otherList = purchaseSampleItemMapper.selectSampleTestProgress((pageNo - 1) * pageSize, pageSize);
//获取orderList数据
List<SampleTestProgressDTO> orderList = sampleTestProgressExtendApiService.getList((pageNo - 1) * pageSize, pageSize);
//将orderList中的数据赋值到otherList中
List<SampleTestProgressDTO> list = otherList.stream().map(map -> orderList.stream()
//判断两个list中ElsAccount是否相等
.filter(m -> Objects.equals(m.getElsAccount(), map.getElsAccount()))
.findFirst().map(m -> {
//将orderList字段赋值到otherList中
map.setSupplierCode(m.getSupplierCode());
map.setSupplierName(m.getSupplierName());
map.setOrderNumber(m.getOrderNumber());
map.setQuantity(m.getQuantity());
map.setOrderDate(m.getOrderDate());
return map;
}).orElse(null))
.filter(Objects::nonNull).collect(Collectors.toList());

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐
所有评论(0)