import java.util.*; public class Map2 { public static void main(String[] args) { Map M = new HashMap(); M.put("John Doe", "Brother"); M.put("Tom Doe", "Cousin"); M.put("Jane Doe", "Sister"); M.put("Todd Hall", "Neighbor"); M.put("Ralph Smith", "Teacher"); /* ------------------------------------------------ entrySet() returns a "Set>" or: a "Set" of items ----------------------------------------------- */ Collection s = M.entrySet(); // Set s = M.entrySet(); /* ------------------------------------------------ Get an iterator over a Set ----------------------------------------------- */ Iterator iter = s.iterator(); // ----------------------------------------- // Shorter: // Iterator iter = M.keySet().iterator(); // ----------------------------------------- /* ------------------------- Iterate over "iter" ------------------------- */ while(iter.hasNext()) { Map.Entry x; // Help variable x = (Map.Entry) iter.next(); // Get next entry System.out.print(x.getKey() + ": "); System.out.println(x.getValue()); } System.out.println(); } }