根据商品id去重,并对同一商品id的商品数量求和,取集合
List<ProductDO> collect = productList.stream()
.collect(Collectors.toMap(ProductDO::getProductId, a -> a, (o1, o2) -> {
o1.setNum(o1.getNum() + o2.getNum());
return o1;
})
).values().stream().collect(Collectors.toList());
标签:流之去,stream,求和,o2,collect,id,o1 From: https://www.cnblogs.com/shirleyxueli/p/16797956.html