// 分组
Map<String, List<ChartDataView>> map = data.stream().map(t -> {
ChartDataView c = new ChartDataView();
c.setDimension1(t.getDimension10());
c.setTarget1(t.getTarget7());
return c;
}).collect(Collectors.groupingBy(ChartDataView::getDimension1));
// 汇总
for (String s : map.keySet()) {
List<ChartDataView> l = map.get(s);
ChartDataView resultItem = new ChartDataView();
BigDecimal sum = l.stream().map(e -> e.getTarget1()).reduce(BigDecimal.ZERO, BigDecimal::add);
resultItem.setDimension1(s);
resultItem.setTarget1(sum);
res.add(resultItem);
}
标签:map,BigDecimal,Stream,汇总,分组,ChartDataView,resultItem
From: https://www.cnblogs.com/jqccan/p/16634773.html