I have a TreeMap that maps String keys to a custom City class. Here is how it is instantiated:
TreeMap<String, City> nameDictionary = new TreeMap<String, City>(new CityNameComparator());
CityNameComparator implementation:
public class CityNameComparator implements Comparator<String>
{
public int compare (String c1, String c2) {
return c1.compareTo(c2);
}
}
I have a method that returns an iterator that should iterate through the map in key-ascii order:
public Iterator<City> getNameIterator(){
return nameDictionary.values().iterator();
}
For some reason the values are returned in the order they were added to the TreeMap. Any ideas?