posted 18 years ago
Hi Nikhil,
What Keith said is correct !
TreeSet is a kind of Set where its elements are sorted by their natural order.
In order to perform the sort, TreeSet uses the Comparator interface which must be implemented by your Person class.
When using Strings for example, there's no problem because String object implements all needed methods properly.
The code below is the changed version for your Person class. Please check it out :
When checking the output you can see that all elements are sorted by age.
Hope that helps.
"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself