posted 12 years ago
They do basically the same thing -- you call the same methods to use them. But there are two main differences: HashMap is faster, but noticeably so only for big collections (thousands of items or more); and if you ask a TreeMap to list all its keys for you (i.e., you call ketSet().iterator()) you'll get all the keys in sorted order. This means that the keys have to implement the Comparable interface, or you have to provide a Comparator when you create the TreeMap. On the other hand, HashMap requires that the keys overridden the hashMap() and equals() methods in a sensible way.