JAVA常用语句

List转为Map(值唯一)

Map myDtoMap = new HashedMap();
    if(!CollectionUtils.isEmpty(myDtoList)){
        merchantDTOMap = myDtoList.stream().collect(Collectors.toMap(MerchantDTO::getOrderId, Function.identity(), (key1, key2) -> key2));
    }

List转为Map(group by)

Map<Long, List<MyInfo>> map =  myInfoList.stream().collect(Collectors.groupingBy(MyInfo::getUserId));

你可能感兴趣的:(JAVA基础)