Write a program in java to demonstrate TreeSet?

import java.util.*;

public class ListTreeSet

{

      public static void main(String arg[])

      {

            TreeSet ListTreeSet=new TreeSet();

            System.out.println("Adding Kundan First Time "+ListTreeSet.add("Kundan"));

            ListTreeSet.add("Suraj");

            ListTreeSet.add("Manish");

            ListTreeSet.add("Ankit");

            System.out.println("Adding Kundan Second Time "+ListTreeSet.add("Kundan"));

            System.out.println("Total Number In ListTreeSet "+ListTreeSet.size());

            Iterator itr=ListTreeSet.iterator();

            while(itr.hasNext())

                  System.out.println(itr.next());

      }

}

List Tree Set.PNG

, , , , ,

Leave a Reply