java1.8从list集合中抽取某个字段转为新的集合以及把list集合按某个字段进行分组

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

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

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


 

你可能感兴趣的:(java)