我在做Map
的研究,我发现如果我故意添加相同的密钥两次,那么地图的大小保持不变。这背后的技术原因是什么?在地图中添加两次相同的密钥
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
这就是Maps的全部要点。 – Pshemo 2012-08-06 16:21:16