我正在研究地图,我发现如果我故意两次添加相同的密钥,那么地图的大小保持不变.这背后的技术原因是什么?
Map map=new HashMap();//HashMap key random order.
map.put("Amit","Java");
map.put("Amit","Java");
检索代码……
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());
}
结果我得到:
There are 1 elements in the map.
Content of Map are...
Amit Java 3943477