Try debugging the code to see what it is doing. Add print statements in the compare and compareTo methods that print out the values being compared and the value that is returned.
The print out will show you why you are getting the results.
OP added a printout. So that will not make him much wiser.
OP must have a look at the API of a TreeSet what the difference is between:
There are three kinds of actuaries: those who can count, and those who can't.
posted 2 weeks ago
printout. So that will not make him much wiser.
The print out from the print statements that I suggested would show what method is called and when it is called and what the results of the call is.
Given that if the OP did not understand what was happening, he could ask.