java8 list long Double 泛型 求和

最近在写数据求和:总结几类,直接贴代码

List–long求和

		Long a = 0L;
        List<Long> list = Arrays.asList(11111L,11111L,11111L,11111L);
        a =  list.stream().mapToLong(Long::longValue).sum();里插入代码片

list—Double求和

 		List<Double> list = Arrays.asList(111.11,111.11,111.11,111.11);
        Double a =  list.stream().mapToDouble(Double::doubleValue).sum();
        System.out.println(a);

list–T 泛型求和

     long num= list.stream().mapToLong(User::getNum).sum();//num
     Double cnt=  list.stream().mapToDouble(ScreenSales::getCnt).sum();//cnt

你可能感兴趣的:(java后端,springboot,java,stream)