java8 list取出重复值、统计数量


List<ImportDeviceReq> list = new ArrayList<>();
//根据device_code去重,取出重复值
List<String> dupList = list.stream().collect(Collectors.groupingBy(ImportDeviceReq::getDeviceCode, Collectors.counting()))
        .entrySet().stream().filter(e -> e.getValue() > 1)
        .map(Map.Entry::getKey).collect(Collectors.toList());
List<String> telephoneList = new ArrayList<>();
//字符串取出重复值
List<String> repeatList = telephoneList.stream().collect(Collectors.groupingBy(e -> e, Collectors.counting()))
          .entrySet().stream().filter(e -> e.getValue() > 1)
          .map(Map.Entry::getKey).collect(Collectors.toList());
List<FeYltTicketBatchReq.IssueTicketInfo> issueTicketInfo = issueTicket.getIssueTicketInfo();
//每个人的服务券数量相加
int sum = issueTicketInfo.stream().mapToInt(FeYltTicketBatchReq.IssueTicketInfo::getTicketCount).sum();


免责声明!

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



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