1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > JDK8中Collectors.toMap方法报Duplicate key xxx错误信息

JDK8中Collectors.toMap方法报Duplicate key xxx错误信息

时间:2021-12-10 08:40:13

相关推荐

JDK8中Collectors.toMap方法报Duplicate key xxx错误信息

两种 list转map方式

方式一:这种方式 重复key的话会报错 Duplicate key xxx

Map deviceDtoMap = JsonUtils.toList(deviceDtoList).stream().collect(Collectors.toMap(DeviceDto::getDeviceId, deviceDto -> deviceDto));

方式二:

Map<String, String> map = deviceDtoList.stream().collect(Collectors.toMap(DeviceDto :: getDeviceId, DeviceDto :: getDeviceId, (value1, value2) -> value2));

方式三:

Map<String, DeviceDto> deviceDtoMap = deviceDtoList.stream().collect(Collectors.toMap(DeviceDto::getDeviceId, Function.identity(),(entity1, entity2) -> entity1));

更详细原文:JDK8中Collectors.toMap方法报Duplicatekey xxx错误信息_张志翔的博客-CSDN博客_collectors.tomap value是集合

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。