Manish said:
gk said:
TreeSet maintains its elements in their natural order, hence iterating
will produce "Apple Banana Cricket " instead of "Apple Cricket Banana"
what is natural order in the above ?
does it want to say, treeset always sorts automatically by
ALPHABATICALLY ?
Yes, in this case - as it contains strings. String implements
comparable, which offers natural ordering. In case of strings, the
natural ordering implies alphabetical sorting. [...]
Almost. The natural ordering for String objects is their
lexicographic order according to the Unicode values of their
individual characters, so (for example) "Aïda" comes after
"Axolotl". For an even more blatant violation of alphabetical
order, note that "Zebra" precedes "aardvark".
Also, "alphabetical order" varies from place to place, even
if you consider only languages written in Latin alphabets. As
far as I know (I'm no expert on this, just someone who once got
a bit of a scolding from a person who was), everybody agrees on
the ordering of the twenty-six unaccented letters, but the
treatment of accented letters is subject to national and linguistic
variation.
See also java.text.Collator and allied classes.