【记录】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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM