TreeSet class is the class that implements NavigableSet interface and NavaigableSet extends SortedSet which extends Set.
TreeSet contains unique elements.
Another important and powerful property is that it maintains ascending order.
To use Tree set we have to import java.util.* package first.
This is simplest way to implement Treeset
TreeSet treeSet = new treeSet();
treeSet.add(A java);
treeSet.add(D java);
treeSet.add(C java);
treeSet.add(B java);
Iterator iterator = treeSet.iterator();
While(iterator.hasNext()){
System.out.println(iterator.next());
}
Now check the output:
A java
B java
C java
D java
0 Comment(s)