I did Map research, and I found that if I add the same key twice, the map size remains the same. What is the technical reason for this?
Map map=new HashMap();//HashMap key random order. map.put("Amit","Java"); map.put("Amit","Java");
Code to retrieve ...
System.out.println("There are "+map.size()+" elements in the map."); System.out.println("Content of Map are..."); Set s=map.entrySet(); Iterator itr=s.iterator(); while(itr.hasNext()) { Map.Entry m=(Map.Entry)itr.next(); System.out.println(m.getKey()+"\t"+m.getValue()+"\t"+ m.hashCode()); }
The result that I get:
There are 1 elements in the map. Content of Map are... Amit Java 3943477
user1579492
source share