1Map map = new HashMap();
2Iterator entries = map.entrySet().iterator();
3while (entries.hasNext()) {
4 Map.Entry entry = (Map.Entry) entries.next();
5 Integer key = (Integer)entry.getKey();
6 Integer value = (Integer)entry.getValue();
7 System.out.println("Key = " + key + ", Value = " + value);
8}
9
1Map<Integer, Integer> map = new HashMap<Integer, Integer>();
2
3// Iterating over keys only
4for (Integer key : map.keySet()) {
5 System.out.println("Key = " + key);
6}
7
8// Iterating over values only
9for (Integer value : map.values()) {
10 System.out.println("Value = " + value);
11}
12
1Map<Integer, Integer> map = new HashMap<Integer, Integer>();
2for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
3 System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
4}
5