已知对象ListSplitProductionOrderItem splitIsNotB MapString BigDecimal releaseTotal过滤掉releaseTotal的key值与splitIsNotB中的字段productId相同的数据并生成新的对象ListOdsMaterialDocumentItem resultList2
你可以使用Java 8的流操作来实现这个过滤和转换的操作。代码如下:
List<OdsMaterialDocumentItem> resultList2 = releaseTotal.entrySet().stream()
.filter(entry -> {
String productId = entry.getKey();
return splitIsNotB.stream().noneMatch(item -> item.getProductId().equals(productId));
})
.map(entry -> new OdsMaterialDocumentItem(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
这段代码使用stream()方法将releaseTotal的键值对转换为流操作,然后通过filter()方法筛选出键值对的键不在splitIsNotB中的数据。接着,通过map()方法将符合条件的键值对转换为OdsMaterialDocumentItem对象。最后,通过collect()方法将转换后的对象收集到一个新的列表中
原文地址: http://www.cveoy.top/t/topic/iTiJ 著作权归作者所有。请勿转载和采集!