import java.util.*; import java.io.*; public class TryhashMap { public static void main(String arg[]) { HashMap ageMap = new HashMap(); ageMap.put("elephant", new Integer(120)); ageMap.put("dog", new Integer(15)); ageMap.put("cat", new Integer(20)); ageMap.put("turtle", new Integer(100)); ageMap.put("human", new Integer(75)); System.out.println("Print out the entire ageMap\n" + ageMap); // search for the value associated with "dog" System.out.println("A dog can live to age " + ageMap.get("dog")); System.out.println(); // keySet returns a set view of the keys contained in this map. System.out.println(ageMap.keySet()); // iterate through the keySet, doing something to each item Iterator itr = ageMap.keySet().iterator(); while (itr.hasNext()) System.out.println(itr.next()); System.out.println(); Iterator itr2 = ageMap.values().iterator(); while (itr2.hasNext()) System.out.println(itr2.next()); } // end main } // end TryhashMap