List分组GroupBy一个字段,如下

  Map<Long, List<BaseOil>> subListMap = baseOilList.stream().filter(x -> x.getSubclassId() != null).collect(Collectors.groupingBy(BaseOil::getSubclassId));

 多个字段,可以将多个字段new到一个实体中,得到分组结果,如下

 Map<MtrlSupplyDailyDtlEntity, List<MtrlSupplyDailyDtlEntity>> collect = dtlList.stream().collect(Collectors.groupingBy(
                record -> new MtrlSupplyDailyDtlEntity(record.getBaseOilId(), record.getBaseOilName(), record.getMtrlStoragePlaceId())));

  

对分组结果也可以筛选过滤

Map<ReportEntity, List<InReport>> entry = subListMap.entrySet().stream().filter(x -> x.getKey().getReportDateT().equals(dateList.get(0)) && x.getKey().getCompanyCode().equals(code)).collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue()));

 

相关文章:

  • 2022-01-10
  • 2021-12-20
  • 2021-10-09
  • 2021-12-11
  • 2021-11-19
  • 2021-09-04
  • 2022-01-10
  • 2021-11-30
猜你喜欢
  • 2021-07-07
  • 2022-12-23
  • 2021-09-11
  • 2021-05-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
相关资源
相似解决方案