我有这样的地图
Map map=new HashMap();//HashMap key random order.
map.put("a",10);
map.put("a",20);
map.put("a",30);
map.put("b",10);
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 2 elements in the map.
Content of Map are...
b 10 104
a 30 127
现在我希望那个键 a 应该有多个值,比如
a 10
a 20
a 30
这样我就应该得到与 a 关联的所有值。请告知我怎样才能实现同样的目标。通过嵌套集合,我希望键 'a' 具有所有三个值。