12345678910111213141516171819202122232425262728293031 |
- import java.util.*;
- import java.util.Map.Entry;
-
-
- public class PhoneBook {
-
- Map<String, List<String>> phoneMap = new TreeMap<String, List<String>>();
- List<String> phoneNumbers = new ArrayList<String>();
-
- public void add(String name, String phoneNumber){
- phoneNumbers.add(phoneNumber);
- phoneMap.put(name, phoneNumbers);
- }
-
- public void remove(String name){
- phoneMap.remove(name);
- }
-
- public String lookup(String name){
- return phoneNumbers.iterator(phoneMap.get(name));
- }
-
- public String reverseLookup(String phoneNumber){
- for(Entry<String, String> entry : phoneMap.entrySet()){
- if(entry.getValue().equals(phoneNumber)){
- return entry.getKey();
- }
- }
- return null;
- }
- }
|