TreeSet in Java

What is TreeSet A NavigableSet implementation based on a TreeMap. The elements are ordered using their natural ordering, or by a Comparator provided at set creation time, depending on which constructor is used. Like HashSet, TreeSet also implements Set interface. Like HashSet, TreeSet allows to store only unique elements in their objects. HashSet is much faster than TreeSet because HashSet has constant-time, whereas TreeSet has log-time for most operations like add, remove and contains. Unlike HashSet, TreeSet offers a few handy methods to deal with the ordered set like first(),…

Continue