What is the reason of the exception message complains about duplicate key but shows the value instead?
List<Employee> employees = new ArrayList<>();
employees.add(new Employee("John", 40));
employees.add(new Employee("John", 30));
Map<String, Integer> map = employees.stream()
.collect(Collectors.toMap(Employee::getName, Employee::getAge));
Instead of show "John" as the duplicated key, it show "40"
Exception in thread "main" java.lang.IllegalStateException: Duplicate key 40
(...)
It has been fixed in JDK 9. Take a look here. https://bugs.openjdk.java.net/browse/JDK-8173464
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With