stream List 转map ,重复的key,value转为集合

  Map> collect = parkingImgs.stream().collect(Collectors.toMap(ParkingImg::getPARKING_ID,
                e -> new ArrayList<>(Arrays.asList(e)),
                (List oldList, List newList) -> {
                    oldList.addAll(newList);
                    return oldList;
                }));

或者

Map> collect = parkingImgs.stream().collect(Collectors.groupingBy(ParkingImg::getPARKING_ID));		

 

你可能感兴趣的:(java)