Write a program in java to demonstrate remove duplication from ArrayList to TreeSet?

import java.util.*;

public class ListAdd

{

      public static void main(String arg[])

      {

            Scanner in=new Scanner(System.in);

            ArrayList ls=new ArrayList();

            TreeSet set=new TreeSet();

            ls.add("Vikrant");

            ls.add("Manish");

            ls.add("Suraj");

            ls.add(3,"Amit");

            ls.add("Manish");

            ls.add("Kanir");

            set.addAll(ls);

            System.out.println("Total Number of Elements is "+ls.size());

            Iterator l=ls.iterator();

            while(l.hasNext())

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

            System.out.println("Total Number of Elements is "+set.size());

            Iterator s=set.iterator();

            while(s.hasNext())

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

      }

}

Remove duplication from ArrayList to Tree Set.PNG

, , , , , , ,

Leave a Reply