jdk-8 lambda使用记录(持续更新中)

  1. 根据指定参数分组并统计数量:
Map<Long, Long> parentRelChildMap = subjectInfoList.stream()
            .collect(Collectors.groupingBy(GoodsSubjectInfo::getParentSubjectId,Collectors.counting()));
  1. 根据list转map(k1,k2)->k2,是确保在key重复下能按指定覆盖规则执行,避免重复key的异常:
Map<String, AreaInfoListDTO> map = list.stream().collect(Collectors.toMap(AreaInfoListDTO::getAreaCode, t->t, (k1,k2)->k2));
  1. list单个参数分组:
Map<String, List<AccountFundNoInfoDO>> customerMap = list.stream().collect(Collectors.groupingBy(
            AccountFundNoInfo::getFundNo, Collectors.toList()));
  1. list多个参数分组:
Map<String, List<CustomerUniqueBaseDO>> customerMap = list.stream().collect(Collectors.groupingBy(t->CharSequenceUtil.format(FORMAT,
            t.getCustomerName(),
            t.getCertificateType(),
            t.getCertificateNum(),
            t.getContactType(),
            t.getContactInfo()) , Collectors.toList()));
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容