首页 > 编程语言 > 详细

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

时间:2020-07-02 14:20:21      阅读:1150      评论:0      收藏:0      [点我收藏+]

 

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

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

原文:https://www.cnblogs.com/wbl001/p/13224233.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!