Duplicate Key in TreeMap

I have the code below for a tree map, where I keep a duplicate key and seem to overwrite the existing one.

TreeMap<String, Integer> tm=new TreeMap<>();
tm.put("vivek", 1);
tm.put("vivek", 2);
System.out.println(tm);

He is typing {vivek=2}. So this means that the card allows rewriting based on the key?

+3
source share
2 answers

TreeMap#public V put(K key, V value) API says

Associates the specified value with the specified key on this map. If the map previously contained a mapping for the key, the old value is replaced.

+6
source

All cards have the same basic properties, one of which is that all keys must be unique. Therefore why keySet()returns a Set.

, , Multimap - .

Map<Integer, List<String>> multiMap;

, , null, , , .

.

+9

All Articles