Java Program To Removed duplicates From ArrayList - Java Programming Interview Quetions @Fresher-Naukri.com

Java Programming Interview Quetions

Java Program To Removed duplicates From ArrayList

* This is also one the common interview when you attend the interview as a fresher or experienced. Here I have provided the java program in a simple way.


import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;


public class ArrayListDuplicateDemo{   

        public static void main(String args[ ]){

              List<Integer> primes = new ArrayList<Integer>( );

             
               primes.add.( 2);
               primes.add.(3);
               primes.add.(5);
               primes.add.(7);
               primes.add.(11);

               System.out.println("list of  primr number : " + primes);

               Set<Integer> primesWithoutDuplicates = new LinkedHashset<Integer>(prime

                prime.clear( );

                primes.addAll(primesWithoutDuplicates);

               System.out.println("list of primes without duplicates : " + primes);

        }

}

Below is the Output for the above Program

list of prime numbers : [2, 3, 5, 7, 7, 11]
list of prime without duplicates : [2, 3, 5, 7, 11]

For more Interview Questions Just click on www.Fresher-Naukri.com.

0 comments 10:

Post a Comment