Map的几种遍历方式
方式1: Iterator<String> iterator = map.keySet().iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); String value = map.get(key); } 方式2: for (String key : map.keySet()) { String value = map.get(key); } 方式3: Iterator<Entry<String, String>> iterator = map.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<String, String> entry = (Map.Entry<String, String>) iterator.next(); String key = entry.getKey(); String value = entry.getValue(); } 方式4: for (Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); } 来源: