Created
December 9, 2015 14:20
-
-
Save eMahtab/9f24cd626d06d62db15e to your computer and use it in GitHub Desktop.
Removing Duplicates from an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Scanner; | |
public class RemoveDuplicate { | |
public static void main(String[] args) { | |
Scanner sc=new Scanner(System.in); | |
int size=sc.nextInt(); | |
int array[]=new int[size]; | |
for(int i=0;i<size;i++){ | |
array[i]=sc.nextInt(); | |
} | |
List<Integer> unique=new ArrayList<Integer>(); | |
for(int i=0;i<size;i++){ | |
if(!unique.contains(array[i])){ | |
unique.add(array[i]); | |
} | |
} | |
System.out.println("After removing duplicates : "+unique); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment