Skip to content

Instantly share code, notes, and snippets.

@eMahtab
Created December 9, 2015 14:20
Show Gist options
  • Save eMahtab/9f24cd626d06d62db15e to your computer and use it in GitHub Desktop.
Save eMahtab/9f24cd626d06d62db15e to your computer and use it in GitHub Desktop.
Removing Duplicates from an array
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