【记录】JAVA8 Stream()遍历求某列总和

 

List<CommonExportDTO> commonList;
// 取字段string转int构建新列表
List<Integer> collect = commonList.stream().map(dto -> Integer.valueOf(dto.getCell6())).collect(Collectors.toList());
// reduce求和 Optional
<Integer> reduce = collect.stream().reduce(Integer::sum); Integer total = reduce.get();

 

参考地址

JDK 1.8 新特性之Stream 详解个人笔记:https://blog.csdn.net/chenhao_c_h/article/details/80691284

实现一个LIST集合中的某个元素的求和: https://www.cnblogs.com/jishumonkey/p/12166541.html

Java8对List<Integer>的求和:https://blog.csdn.net/hsz2568952354/article/details/89886743

posted @ 2020-07-02 13:43  -天道酬勤-  阅读(10679)  评论(0编辑  收藏  举报