Originally posted by Guangcheng Zhou:
Yes, so is compareTo() method used in adding elements? I thought only hashCode() and equals() were used.
It uses either natural order if the Comparator is not provided, or an order specified by Comparator.compareTo() method.
It has nothing to do with Object's hashCode() or equals() methods.
However, the elements must be mutually comparable.