java.lang.IllegalStateException: Duplicate key 0
https://blog.csdn.net/qq_40366738/article/details/114754348
集合转map,重复key的问题
public class Test {
public static void main(String[] args) {
List<Map.Entry> list = new ArrayList<>();
for (int i = 0; i < 3; i++) {
Map.Entry entry = new AbstractMap.SimpleEntry<>(1,i);
list.add(entry);
}
Map<Object, Object> map = list.stream().collect(
Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
//以最后一个元素为准,更新
//(e1,e2) -> e2
//以第一个元素为准,不更新
(e1,e2) -> e1
));
System.out.println(map);
}
}