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

相关文章:

  • 2021-11-30
  • 2021-10-09
  • 2021-07-17
  • 2021-09-06
  • 2022-12-23
  • 2022-12-23
  • 2022-02-03
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2022-01-01
相关资源
相似解决方案