Map<String, AstmAbsAssetPO> dealNoList = absAssetPOList.stream().collect(Collectors.toMap(AstmAbsAssetPO::getBusiNo, item -> item)); for (AstmAbsAssetPO assetPO : absFromDb) { AstmAbsAssetPO absAssetPO = dealNoList.get(assetPO.getBusiNo()); assetPO.setPoolId(absAssetPO.getPoolId()); assetPO.setTermTimes(absAssetPO.getTermTimes()); assetPO.setSoldDate(absAssetPO.getSoldDate()); assetPO.setSealDate(absAssetPO.getSealDate()); assetPO.setUpdatedBy(absAssetPO.getUpdatedBy()); assetPO.setUpdatedTime(absAssetPO.getUpdatedTime()); updatePOList.add(assetPO); busiNoUnRepeat.remove(assetPO.getBusiNo()); } 把这段Java代码用一个stream流写出来
时间: 2023-07-14 14:13:15 浏览: 430
在Java 8中将List转换为Map对象方法
List<AstmAbsAssetPO> absAssetPOList = ...; // 假设已经有一个 AstmAbsAssetPO 类型的列表 absAssetPOList
List<AstmAbsAssetPO> absFromDb = ...; // 假设已经有一个 AstmAbsAssetPO 类型的列表 absFromDb
Map<String, AstmAbsAssetPO> dealNoList = absAssetPOList.stream()
.collect(Collectors.toMap(AstmAbsAssetPO::getBusiNo, Function.identity()));
List<AstmAbsAssetPO> updatePOList = absFromDb.stream()
.peek(assetPO -> {
AstmAbsAssetPO absAssetPO = dealNoList.get(assetPO.getBusiNo());
assetPO.setPoolId(absAssetPO.getPoolId());
assetPO.setTermTimes(absAssetPO.getTermTimes());
assetPO.setSoldDate(absAssetPO.getSoldDate());
assetPO.setSealDate(absAssetPO.getSealDate());
assetPO.setUpdatedBy(absAssetPO.getUpdatedBy());
assetPO.setUpdatedTime(absAssetPO.getUpdatedTime());
})
.collect(Collectors.toList());
阅读全文