Does HashMap allow duplicate keys when putting same key with different value?
Explanation
This reference explains really well.
HashMap does NOT allow duplicate keys so when we try to
Map mymap = new HashMap();
mymap.put("1","one");
mymap.put("1","not one");
mymap.put("1","surely not one");
System.out.println(mymap.get("1"));
We get “surely not one”, the latest value. Why?
The map simply drops its reference to the value.
And by definition, put replaces the previous value associated with the key in HashMap.