其他分享
首页 > 其他分享> > Stream 分组,BigDecimal求和汇总

Stream 分组,BigDecimal求和汇总

作者:互联网

                // 分组
		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,sum,分组,ChartDataView,stream,resultItem
来源: https://www.cnblogs.com/jqccan/p/16634773.html