You just need a compareTo method, which you have already, or you could supply a comparator in the constructor.
I don't know the inner workings of a tree set, but I could imagine it runs through the collection calling compareTo on the elements already in there till it finds the right sort position or an equal object (compareTo = 0), in that case the element is not added.
http://docs.oracle.com/javase/1.4.2/docs/api/java/util/TreeSet.html
Since 1.2
Sorting:
You just need a compareTo method, which you have already, or you could supply a comparator in the constructor.
I don't know the inner workings of a tree set, but I could imagine it runs through the collection calling compareTo on the elements already in there till it finds the right sort position or an equal object (compareTo = 0), in that case the element is not added.