其他分享
首页 > 其他分享> > 从list集合中抽取getId转为新的集合

从list集合中抽取getId转为新的集合

作者:互联网

从list集合中抽取getId转为新的集合:
List<NatCustomers> natCustomersList = natCustomersService.queryListByPage(0,1000);
List<Integer> customerIds = natCustomersList.stream().map(NatCustomers::getId).collect(Collectors.toList());

把list集合按getCustomerId字段进行分组:

List<ConsumptionStatistics> consumptionStatistics = natServicesService.getConsumptionStatistics(paramMap);
Map<Integer, List<ConsumptionStatistics>> collect = consumptionStatistics.stream().collect(Collectors.groupingBy(ConsumptionStatistics::getCustomerId));

标签:stream,list,List,getId,collect,集合
来源: https://www.cnblogs.com/jxbo/p/15402570.html