This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I thought that the output would be Bill Carl Kathy because TreeMap is sorted by natural order, but output is Bill Kathy Carl. Why? Approximately the same example with TreeSet print out results in alfabetical (natural) order. Thanks in advance. [ April 05, 2004: Message edited by: Serghei Jelauc ]
The TreeMap class guarantees that the map will be in ascending key order, sorted according to the natural order for the key's class (see Comparable), or by the comparator provided at creation time, depending on which constructor is used.
The sorting in TreeMap is done on the keys and not the values.Since you have given the keys as 'a','b','c'.....it will be sorted in that order...
Do not dwell in the past, do not dream of the future, concentrate the mind on the present moment.