posted 18 years ago
Hi,
the answer is D. Natural order is natural order. :-) That means, it is alphabetical order for Strings, numerical order for Numbers, date-related order for Dates, etc. For your own classes, the natural order is defined by the compareTo method of the Comparable interface which you have to implement in order to be able to add more than one element to the SortedSet (or you have to specify Comparator at the time of SortedSet creation).
The SortedMap is for storing pairs of keys and values, not "elements" as required in your questions. (It is sorted by keys.)
You can use your own Comparator to override the natural order. See the documentation of TreeSet.
Hope that helped.
Jan
Anybody knows about a job for <a href="http://cern.ch/jvalenta/valenta-cv.pdf" target="_blank" rel="nofollow">SCJP5.0, Ph.D. in Software Engineering, 2 years Java, C, C++</a> in Montreal, QC, Canada? Thanks!