TreeSet in Java

TreeSet class implements the Set interface that uses a tree for storage. The objects of this class are stored in ascending order. Also, it inherits AbstractSet class and implements NavigableSet interface. It contains only unique elements like HashSet. In TreeSet class, access and retrieval time are faster.
```
import java.util. * ;
public class TreeSetExample {
	public static void main(String args[]) {
		TreeSet < String > s = new TreeSe < String > ();
		s.add("a");
		s.add("c");
		s.add("b");
		Iterator < String > itr = s.iterator();
		while (itr.hasNext()) {
			System.out.println(itr.next());
		}
	}
}
```
Below are some of the methods of Java TreeSet class,
Method | Description
----- | -----
 boolean addAll(Collection c) | Add all the elements in the specified collection to this set.
 boolean contains(Object o) | Returns true if the set contains the specified element.
 boolean isEmpty() | Returns true if this set contains no elements.
 boolean remove(Object o) | Remove the specified element from the set.
 void add(Object o) | Add the specified element to the set.
 void clear() | Removes all the elements from the set.
 Object clone() | Return a shallow copy of this TreeSet instance.
 Object first() | Return the first element currently in the sorted set.
 Object last() | Return the last element currently in the sorted set.
 int size() | Return the number of elements in the set.