Lennie De Villiers wrote:Hi,
I read that when you use a TreeSet you need to specify which order it must sort with, if it got a natural order (like with a Byte, String, Date etc) then it will use it else you need to specify.
What happens if I don't specify a order?
cheers
Lennie
Basically, if you specify a comparator, it will use that, regardless of the natural sort order. If you don't then it will use the natural sort order, which means that it will use the comparable interface of the elements.
If you don't specify a comparator, and the elements are not comparable, then you will get a cast exception, when the treeset tries to access the comparable interface.
Henry