当需求Key也需求Value时(最常用) entrySet Map<Character,Integer> map = new HashMap<>(); map.put('a',6); map.put('b',233); map.put('c',969); //## 当需求Key也需求Value时(最常用) for (Map.Entry<Character,Integer> entry: map.entrySet() ) { System.out.println("第一种方法"); System.out.println("Key:" + entry.getKey()); System.out.println("Value:" + entry.getValue()); } 当需求Key时 keySet Map<Character,Integer> map = new HashMap<>(); map.put('a',6); map.put('b',233); map.put('c',969); for (Character c : map.keySet()){ System.out.println("第二种方法"); System.out.println("Key:" + c); } 当需求Value时 Values Map<Character,Integer> map = new HashMap<>(); map.put('a',6); map.put('b',233); map.put('c',969); for(Integer i: map.values()){ System.out.println("第三种方法"); System.out.println("Value:" + i); }