Map实现集合中相同属性元素(合并去重)

               HashMap<String, LogisticsShipmentDTO.LogisticsShipmentOpt> map = Maps.newHashMap();
                            //根据sku+ 市场--合并入库数量及总运费
                            shipmentOptList.stream().forEach(shipmentOpt -> {
                                LogisticsShipmentDTO.LogisticsShipmentOpt opt = map.get(shipmentOpt.getSku());
                                if (Objects.nonNull(opt)) {
                                    shipmentOpt.setQty(new BigDecimal(shipmentOpt.getQty()).add(new BigDecimal(opt.getQty())).toString());
                                    shipmentOpt.setTotalFeight(shipmentOpt.getTotalFeight().subtract(opt.getTotalFeight()));
                                    map.put(shipmentOpt.getSku(), shipmentOpt);
                                } else {
                                    map.put(shipmentOpt.getSku(), shipmentOpt);
                                }
                            });
原文地址:https://www.cnblogs.com/zrboke/p/14918350.html