The output of the following code sample is:
{1--e=e2, 2--e1=e1}
package com.sid.practice;
import java.util.HashMap;
import
The reason behind the output {1--e=e2, 2--e1=e1} is :
Map do not replaces key it only does so for value when there is match (present on the basis of key) in the existing Map. So applies in this case:
Here e is equal to e2 for Map. When Map search for location to put m.put(e2, "e2"); it goes to location where e--"e1" is present and replaces "e1" by "e2" and leaves the key i.e e in this case intact