I read that HashTable can map same key to multiple values. That’s what collision is.
Now I run the program like this:
Dictionary<String,String> hTable = new Hashtable<String,String>();
hTable.put("a", "aa");
hTable.put("a", "ab");
System.out.println(""+hTable.get("a"));
My thinking says I should get aa and ab.
But actual output is ab
Why is it so? Where is the collision then?
There is no collision. A HashTable entry maps a key to only one value.
The third line in your sample:
replaces the mapping from
atoaawith a mapping fromatoab.After your four lines of code complete execution,
hTablehas only one mapping:atoab.