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();
posted @ 2021-05-31 14:22  cchilei  阅读(9148)  评论(0编辑  收藏  举报