I'm trying to create a map of cities and temperature, but it's throwing an IllegalArgumentException. Here's what I'm doing:
Map<String, Integer> tempMap = Map.of("London", 13, "Paris", 17, "Amsterdam", 13,
"Madrid", 21, "Rome", 19, "London", 13, "Bonn", 14,
"Moscow", 7, "Barcelona", 20, "Berlin", 15);
If I add them one by one there's no problem:
Map<String, Integer> tempMap = new Hashmap<>(); // or LinkedHashMap
tempMap.put("London", 13);
tempMap.put("Madrid", 21);
tempMap.put("Moscow", 7);
// etc.
Why does this happen? Aren't the contents supposed to be the same?