public static void main(String[] args) { HashMap<String,String> map = new HashMap<>(); map.put("1","A"); map.put("2","B"); map.put("3","C"); map.put("4","D"); map.put("5","E"); map.put("6","F"); //遍历的方式1 Set<String> keys = map.keySet(); for (String key : keys) { System.out.println(key+"-->"+map.get(key)); } //遍历的方式2 Set<Map.Entry<String, String>> entries = map.entrySet(); for (Map.Entry<String, String> entry : entries) { String key = entry.getKey(); String value = entry.getValue(); System.out.println(key+"-->"+value); } //遍历的方式3 jdk8.0以后开始的新技术 map.forEach((k,v)->{ System.out.println(k+"-->"+v); }); }
标签:map,遍历,java,String,System,key,put From: https://www.cnblogs.com/xst0716/p/16622509.html