All:
This code from the
JavaBeat SCJP1.6 bank of questions focusing on NavigableSet:
The result of this run is "3" and I understand this result is because by the time we reach line "sysprint 2", "3" will be the last entry in the ranks TreeSet. What is confounding me is the sorting of the elements in the TreeSet. I am told that the compareTo() method in the Rank class "tries to sort the elements in descending order". Well, what displays after the execution of the "sysprint 1" line of code is:
4
5
1
3
2
Quite possibly the answer to my question is staring me in the face and I just don't see it. Can anybody please explain to me why, given the configured compareTo() method in the Rank class, the order of the elements in the ranks treeset is not in true descending order? Why am I wrong when I am expecting the elements in the TreeSet to look like:
5
4
3
2
1
??
Thank you for your time.
Gary