Map<String, String> map = new HashMap<String, String>();
map.put("1"."tom");
map.put("2"."rose");
map.put("3"."jack");
map.put("4"."alex");
// The first way to iterate output;Set<? > keyset = map.keySet();for(Object key : keyset){
Object value = map.get(key);
System.out.println(key + ":" + value);
}
// The second way to iterate output;
Set<Entry<String,String>> set = map.entrySet();
for (Entry<String,String> entry : set) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
Copy the code