import java.util.*; public class JavaMap { 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"); // Get a set of the entries Set s = M.entrySet(); // Get an iterator Iterator iter = s.iterator(); // Shorter: // Iterator iter = M.keySet().iterator(); // Display elements while(iter.hasNext()) { Map.Entry x; x = (Map.Entry) iter.next(); System.out.print(x.getKey() + ": "); System.out.println(x.getValue()); } System.out.println(); }