Map<String,String> map = new HashMap<String,String>();
map.put("pant1", "11");
map.put("pant2", "12");
map.put("pant3", "13");
map.put("pant4", "14");
// 遍历Map方式一
Iterator<String> it = map.keySet().iterator();
while(it.hasNext()) {
String name = it.next();
System.out.println( name + " - " + map.get(name));
}
// 遍历Map方式二
for(Entry<String, String> entry : map.entrySet()) {
System.out.println(entry.getKey() + " - " + entry.getValue());
}
map.put("pant1", "11");
map.put("pant2", "12");
map.put("pant3", "13");
map.put("pant4", "14");
// 遍历Map方式一
Iterator<String> it = map.keySet().iterator();
while(it.hasNext()) {
String name = it.next();
System.out.println( name + " - " + map.get(name));
}
// 遍历Map方式二
for(Entry<String, String> entry : map.entrySet()) {
System.out.println(entry.getKey() + " - " + entry.getValue());
}