I stumbled upon the implementation of a TreeSet in which, by the condition of the problem, you need to do sorting in ascending order without repeats and in one of the showy solutions they do it simply through TreeSet ... But as I recall, TreeSet does not remove repetitions but simply adds in increasing order ... Or ?

  • 2
    the same elements cannot be stored in the set; what exactly is considered equal depends on the equals () function. So yes, this solution will do. - pavel
  • @pavel In TreeSet sameness does not depend on equals, but on compare / compareTo. - Roman

1 answer 1

All classes that implement the Set (for example, HashSet , LinkedHashSet , TreeSet ) can contain only unique elements .