1.1 集合多字段分组求和
Map<List<String>, Double> sumQty = list.stream().collect(Collectors.groupingBy(f -> Arrays.asList(f.getMatnr(), f.getWerks()), Collectors.summingDouble(p -> {
return p.getMenge().doubleValue();
})));
1.2 获取字段去重集合
List<String> materialCodes = list.stream().map(QuotaReport::getMaterialCode).distinct().collect(Collectors.toList());
1.3、list转map
materialMinPrices.stream().collect(Collectors.toMap(s -> {
return s.getMaterialCode() + s.getAllExtraAttributesBaseId();
}, QuotaReportVO::getMinPrice))
plantDTOList.stream().collect(Collectors.toMap(BasePlantDTO::getPlantCode,basePlantDTO -> basePlantDTO))
1.4、集合中某个字段值重复次数
Map<String, Long> columnCountMap = entityList.stream().collect(Collectors.groupingBy(PurchaseFocusConfig::getCloumnCode, Collectors.counting()));
List<String> repeatColumns = columnCountMap.entrySet().stream().filter(entry -> entry.getValue() > 1).map(entity -> entity.getKey()).collect(Collectors.toList());
1.5、Arrays转为List
Arrays.asList(new String[]{"priceDifference","price"}.clone());
1.6、单字段求和
list.stream().mapToDouble(p -> p.getDemandQty().doubleValue()).sum()