Skip to content

Instantly share code, notes, and snippets.

@dmnugent80
Last active August 29, 2015 14:13
Show Gist options
  • Save dmnugent80/0d55cc1d9a84ea55b4b8 to your computer and use it in GitHub Desktop.
Save dmnugent80/0d55cc1d9a84ea55b4b8 to your computer and use it in GitHub Desktop.
Delete Duplicates in an array
//Delete duplicates in an array
public static int[] deleteDuplicates( int[] arrayWithDups ){
ArrayList<Integer> arrayNoDups= new ArrayList<Integer>();
for (int i=0; i < arrayWithDups.length; i++){
if (!arrayNoDups.contains(arrayWithDups[i])){
arrayNoDups.add(arrayWithDups[i]);
}
}
int[] arrayPrimitive = new int[arrayNoDups.size()];
for (int i=0; i < arrayNoDups.size(); i++){
arrayPrimitive[i] = arrayNoDups.get(i);
}
return arrayPrimitive;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment