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();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM