hashmap import java.util.*; public class HashMapTest { public static void printElements(Collection c) { Iterator it=c.iterator(); while(it.hasNext()) { System.out.println(it.next()); } } public static void main(String []args) { HashMap hm=new HashMap(); hm.put("1", "zhang3"); hm.put("2", "li4"); hm.put("3", "wang5"); System.out.println(hm.get("1")); System.out.println(hm.get("2")); System.out.println(hm.get("3")); Set keys=hm.keySet(); System.out.println("-----------keys---------"); printElements(keys); Collection values=hm.values(); System.out.println("-----------values---------"); printElements(values); Set entrySets =hm.entrySet(); System.out.println("------------entrySets-----------"); printElements(entrySets); Iterator it=entrySets.iterator(); while(it.hasNext()) { Map.Entry me=(Map.Entry)it.next(); System.out.println(me.getKey()+" = "+me.getValue()); } }