1、根据指定参数分组并统计数量:
Map<Long, Long> parentRelChildMap = subjectInfoList.stream()
.collect(Collectors.groupingBy(GoodsSubjectInfo::getParentSubjectId,Collectors.counting()));
2、根据list转map(k1,k2)->k2,是确保在key重复下能按指定覆盖规则执行,避免重复key的异常:
Map<String, AreaInfoListDTO> map = list.stream().collect(Collectors.toMap(AreaInfoListDTO::getAreaCode, t->t, (k1,k2)->k2));
3、list单个参数分组:
Map<String, List<AccountFundNoInfoDO>> customerMap = list.stream().collect(Collectors.groupingBy(
AccountFundNoInfo::getFundNo, Collectors.toList()));
4、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()));
|