HashMapmap= new HashMap ();
map.put(1,"zhangsan");
map.put(2,"lisi");
map.put(3,"wangwu");
//比较推荐这种方式,还有另外一种方式!
for(Map.Entryentry : map.entrySet()){
System.out.println(entry.getKey() + ":" + entry.getValue());
}
//方式二
Set set = map.entrySet();
Iteratori = set.iterator();
while(i.hasNext()){
System.out.println(map.get(i.next()));
}
//方式三
for (Integer key : map.keySet()) {
Integer value = map.get(key);
System.out.println("Key = " + key + ", Value = " + value);
}