import java.util.*; /** * Created by leon on 1/23/18. */ public class PhoneBook { //private String name; //private String phoneNum; TreeMap phoneListByName = new TreeMap(); TreeMap phoneListByNum = new TreeMap(); public void add(String name, String phoneNumber){ phoneListByName.put(name, phoneNumber); phoneListByNum.put(phoneNumber, name); } public void remove(String name){ String phoneNumber = lookUp(name); phoneListByName.remove(name); phoneListByNum.remove(phoneNumber); } public String lookUp(String name){ return phoneListByName.get(name); } public String reverseLookUp(String phoneNumber){ return phoneListByNum.get(phoneNumber); } public void display(){ Set set = phoneListByName.entrySet(); //Set set2 = phoneListByNum.entrySet(); Iterator i = set.iterator(); while(i.hasNext()){ Map.Entry name = (Map.Entry)i.next(); System.out.println(name.getKey() + ": " + name.getValue()) ; } } }