public class PostalCodeDB { // each key is a postal code, its associated value is a set of cities private Map codeToCityMap; // constructs an empty database public PostalCodeDB() { codeToCityMap = new HashMap(); } // returns the set of cities associated with postalCode if that code is in the database, otherwise returns null public Set getCitiesForCode(String code) { return (Set) codeToCityMap.get(code); } // adds a new city, postalCode pair to this database public void addCityCodePair(String code, String city) { Set citySet = getCitiesForCode(code); if( citySet == null ) { citySet = new HashSet(); codeToCityMap.put(code, citySet); } citySet.add(city); } }