一、entrySet()
Map <String,String> map = new HashMap<String,String>();
map.put("0", "0");
map.put("1", "1");
for(Map.Entry<String, String> entry : map.entrySet()){
String mapKey = entry.getKey();
String mapValue = entry.getValue();
System.out.println(mapKey+":"+mapValue);
}
二、keySet() 或者 values()
Map <String,String> map = new HashMap<String,String>();
map.put("0", "0");
map.put("1", "1");
//key
for(String key : map.keySet()){
System.out.println(key + "value:"+ map.get(key));
}
//value
for(String value : map.values()){
System.out.println(value);
}
三、entrySet() 外加 Iterator遍历
Iterator<Entry<String, String>> entries = map.entrySet().iterator();
while(entries.hasNext()){
Entry<String, String> entry = entries.next();
String key = entry.getKey();
String value = entry.getValue();
System.out.println(key+":"+value);
}