I was wondering what happens to the earlier values in the case of duplicate/overwritten keys. Didn't find any documentation regarding the same.
Case 1: We overwrite values for a key
Case 2: Duplicate key
Map mymap = new HashMap();
mymap.put("1","one");
mymap.put("1","not one");
mymap.put("1","surely not one");
//the following line is case 2 for duplicate
//mymap.put("1","one");
System.out.println(mymap.get("1"));
Case 1: we get "surely not one" Case 2: we get "one"
But what happens to the other values? I was teaching basics to a student and I was asked this. Is the map
like a bucket where the last value is dereferenced (but in memory?)
thx.