list中的对象,按照某一个属性分组,并且按照另外一个属性将其值相加

 elecCompanyElecEnergy.parallelStream().collect(Collectors.groupingBy(d -> d.getElecUserNo(), Collectors.toList()))
                   .forEach((id, groupList) -> {
                       groupList.stream().reduce(
                               (a, b) -> new ElecCompanyElecEnergy()
                                       .setUseYear(a.getUseYear())
                                       .setElecOutNum(a.getElecOutNum())
                                       .setCompanyName(a.getCompanyName())
                                       .setRegionId(a.getRegionId())
                                       .setIndustryId(a.getIndustryId())
                                       .setElecNum(a.getElecNum().add(b.getElecNum()))
                       ).ifPresent(resultList::add);
                   });

你可能感兴趣的:(问题解决,java)