Here is a Java Program to Demonstrate the TreeSet
Output of Above Java Program
a
b
c
import java.util.Iterator; import java.util.SortedSet; import java.util.TreeSet; class SSorted { public static void main(String[] argv) throws Exception { SortedSet<String> set = new TreeSet<String>(); set.add("b"); set.add("c"); set.add("a"); Iterator it = set.iterator(); while (it.hasNext()) { Object element = it.next(); System.out.println(element); } String[] array = (String[]) set.toArray(new String[set.size()]); } }
Output of Above Java Program
a
b
c