import java.util.*; public class example4 { // the Map! Map phonebook = new HashMap(); // change implementation to a TreeMap by substituting the next line // Map phonebook = new TreeMap(); // constructor public example4(String n[], String nums[]) { for(int i=0; i< n.length; i++) phonebook.put( n[i], nums[i] ); } public static void main(String[] args) { // data String [] names = { "Lefty", "Guarav", "Wong", "Rupamay" }; String [] extns = { "4873", "4810", "3769", "0" }; // get an instance of this class example4 ex = new example4( names, extns ); // dump out the map System.out.println("map: " + ex.phonebook); // get the mappings Set> s = ex.phonebook.entrySet(); // iterate over the mappings // for (Iterator i = s.iterator(); i.hasNext(); ) { for (Map.Entry me : s) { Object ok = me.getKey(); Object ov = me.getValue(); System.out.print("key=" + ok ); System.out.println(", value=" + ov ); } } }