import java.util.*; public class MyTestMap { public static void main(String[] args) { int i; Integer freq; String s; HashMap M = new HashMap(4); M.put("a", 1); System.out.println(M); M.put("b", 1); System.out.println(M); M.put("c", 1); System.out.println(M); M.put("d", 1); System.out.println(M); M.put("e", 1); System.out.println(M); M.remove("a"); System.out.println(M); M.remove("b"); System.out.println(M); M.put("e", 1); System.out.println(M); System.out.println(M.size() + " words"); Collection c = M.keySet(); /* ------------------------------------------------ Get an iterator over a Set ----------------------------------------------- */ Iterator iter = c.iterator(); /* ------------------------- Iterate over "iter" ------------------------- */ while(iter.hasNext()) { String x; // Help variable x = (String) iter.next(); // Get next entry System.out.println(x); } System.out.println(); } }