java8处理集合中包含数组形式数据

public static void main(String[] args) {
		List list = new ArrayList<>();
		Object[] aa = {"aa",new BigDecimal("123.455")};
		Object[] bb = {"bb",new BigDecimal("1565.475")};
		Object[] cc = {"cc",new BigDecimal("568.5")};
		Object[] dd = {"dd",new BigDecimal("12.45")};
		Object[] ee = {"ee",new BigDecimal("3.785")};
		list.add(aa);
		list.add(bb);
		list.add(cc);
		list.add(dd);
		list.add(ee);
		//截取集合
		List lastList = list.subList(0, 4);
		//求总和
		final BigDecimal reduce = lastList.stream().map(object -> (BigDecimal) object[1]).reduce(BigDecimal.ZERO, BigDecimal::add);
		//求平均值
		System.out.println("------"+reduce.divide(new BigDecimal("4"),2, BigDecimal.ROUND_HALF_UP));
	}

运行结果:

------567.47

 

你可能感兴趣的:(java)