stream 流 集合 根据某个字段去重 + 提出多个字段生成新集合
List<WebCouponIdAndNameDTO> webCouponIdAndNameDTOList = new ArrayList<>(); if (CollectionUtil.isEmpty(couponDOByCodeList)) { return webCouponIdAndNameDTOList; }
//根据 code去重 webCouponIdAndNameDTOList = couponDOByCodeList.stream() .collect(Collectors.collectingAndThen( Collectors.toCollection( () -> new TreeSet<> (Comparator.comparing(CouponDO::getCpnCode))), ArrayList::new))
//取出三个字段 组成新集合 .stream().map(e -> new WebCouponIdAndNameDTO(e.getCpnName(), e.getCpnCode(), e.getCpnCode())) .collect(Collectors.toList());
标签:Collectors,stream,webCouponIdAndNameDTOList,getCpnCode,字段,集合,new From: https://www.cnblogs.com/zq1003/p/16903714.html