java元帅

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1、list<dto>

List<CollectionItemsTemp> itemsList = new ArrayList<>();
List<String> nameList = new ArrayList<>();
        if (ToolUtil.isNotEmpty(itemsList) && itemsList.size() > 0){
            nameList = itemsList.stream().collect(Collectors.groupingBy(CollectionItemsTemp::getShortName, Collectors.counting()))
                    .entrySet().stream().filter(e -> e.getValue() > 1)
                    .map(Map.Entry::getKey).collect(Collectors.toList());
        }

        if (ToolUtil.isNotEmpty(nameList) && nameList.size()>0){
            sj.add("表格中存在重复..称:"+nameList.toString());
            return new Resp(HttpStatus.INTERNAL_SERVER_ERROR.value(), sj.toString(), null);
        }

2、list<String>

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

3、

List<FeYltTicketBatchReq.IssueTicketInfo> issueTicketInfo = issueTicket.getIssueTicketInfo();
//每个人的服务券数量相加
int sum = issueTicketInfo.stream().mapToInt(FeYltTicketBatchReq.IssueTicketInfo::getTicketCount).sum();

 

posted on 2022-09-01 16:39  java元帅  阅读(250)  评论(0编辑  收藏  举报