Your original code will run with the above change. The rule being simple. If you want to sort using a comparator then you need to pass the comparator in the TreeSet's constructor. Otherwise by default TreeSet assumes that the objects in the Set implement the Comparable interface.
Joined: Sep 13, 2008
Yes. I got it.. Thanks Wouter,Santiago and Harvinder !!!