See Also: TreeMap Members
A map whose entries are sorted by their keys. All optional operations such as TreeMap.put(K, V) and TreeMap.remove(java.lang.Object) are supported.
This map sorts keys using either a user-supplied comparator or the key's natural order:
When the ordering is not consistent with equals the behavior of this class is well defined but does not honor the contract specified by Java.Util.IMap. Consider a tree map of case-insensitive strings, an ordering that is not consistent with equals:
java Example
TreeMap map = new TreeMap(String.CASE_INSENSITIVE_ORDER); map.put("a", "android"); // The Map API specifies that the next line should print "null" because // "a".equals("A") is false and there is no mapping for upper case "A". // But the case insensitive ordering says compare("a", "A") == 0. TreeMap // uses only comparators/comparable on keys and so this prints "android". System.out.println(map.get("A"));