<分区>
List<String> strings = Arrays.asList("3","55","3");
Map<String,Integer> map = strings
.stream()
.collect(Collectors.toMap(s ->s, s -> s.length()));
返回
java.lang.IllegalStateException: Duplicate key 1
我期望重复键 3 的位置
标签 java java-stream
<分区>
List<String> strings = Arrays.asList("3","55","3");
Map<String,Integer> map = strings
.stream()
.collect(Collectors.toMap(s ->s, s -> s.length()));
返回
java.lang.IllegalStateException: Duplicate key 1
我期望重复键 3 的位置
最佳答案
这已在 Java 9 中修复。现在错误消息是正确的:
java.lang.IllegalStateException: Duplicate key 3 (attempted merging values 1 and 1)
关于java - Collectors.toMap() 中的错误报告是否已损坏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49556845/