I think you are asking two questions.
1, Why does your code work?
As Avi wrote on this topic :
If you do not override the hashCode () method, your class inherits the default hashCode () method from Object, which gives each object a separate hash code. This means that t1 and t2 have two different hash codes, even if you compared them, they would be equal. Depending on the specific implementation of the hash card, the card is free to store them separately.
This means that he does not have to store them separately, but he can. Try this code:
TreeSet<ComparisonLogic> set = new TreeSet<ComparisonLogic>(); set.add(new ComparisonLogic("A", "A")); set.add(new ComparisonLogic("A", "B")); set.add(new ComparisonLogic("A", "C")); set.add(new ComparisonLogic("B", "A")); set.add(new ComparisonLogic("B", "B")); set.add(new ComparisonLogic("B", "C")); set.add(new ComparisonLogic("C", "A")); set.add(new ComparisonLogic("C", "B")); set.add(new ComparisonLogic("C", "C")); set.add(new ComparisonLogic("A", "A")); System.out.println(set.remove(new ComparisonLogic("A", "A"))); System.out.println(set.remove(new ComparisonLogic("A", "B"))); System.out.println(set.remove(new ComparisonLogic("A", "C"))); System.out.println(set.remove(new ComparisonLogic("B", "A"))); System.out.println(set.remove(new ComparisonLogic("B", "B"))); System.out.println(set.remove(new ComparisonLogic("B", "C"))); System.out.println(set.remove(new ComparisonLogic("C", "A"))); System.out.println(set.remove(new ComparisonLogic("C", "B"))); System.out.println(set.remove(new ComparisonLogic("C", "C")));
The output for me was as follows:
true true true false false false false false false
This means that some of them were there, some of them were not.
2. What does it mean when javadocs for Treeset says: "Does this class implement the Set interface supported by the TreeMap instance?
This means that the TreeSet class in java 1.7 looks like this:
public class TreeSet<E> extends AbstractSet<E> implements NavigableSet<E>, Cloneable, java.io.Serializable { private transient NavigableMap<E,Object> m; TreeSet(NavigableMap<E,Object> m) { this.m = m; } ... (lots of other code) public boolean contains(Object o) { return m.containsKey(o); } etc.
This means that under the TreeSet class there is a map, and there are many methods that are delegated only to it.
Hope I can help.