Here is a Java Program to Demonstrate TreeSet.
Output of Above Java Program
[A, B, C, D, E, F]
import java.util.*; class TreeSetDemo { public static void main(String args[]) { // Create a tree set TreeSet ts = new TreeSet(); // Add elements to the tree set ts.add("C"); ts.add("A"); ts.add("B"); ts.add("E"); ts.add("F"); ts.add("D"); System.out.println(ts); } }
Output of Above Java Program
[A, B, C, D, E, F]