{
Map<String, String> map = new HashMap<String, String>();
map.put("1","qu");
map.put("2","san");
map.put("3","tao");
//1 二次取值
System.out.println("map.keySet()");
for (String key : map.keySet()) {
System.out.println("key-" + key + "value-" + map.get(key));
}
//2 通过Map.entrySet使用iterator遍历key和value
Iterator<Map.Entry<String,String>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String,String> entry = it.next();
System.out.println("key-" + entry.getKey() + "value-" + entry.getValue());
}
//3 比较推荐 尤其是容量大时
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println("key-" + entry.getKey() + "value-" + entry.getValue());
}
//4 Map.values()遍历所有的value,但不能遍历key
for (String s : map.values()) {
System.out.println("value-" + s);
}
}