Skip to content

Instantly share code, notes, and snippets.

@thmain
Created June 18, 2017 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/1fec80ad26bc0c04a988315deda19d5d to your computer and use it in GitHub Desktop.
Save thmain/1fec80ad26bc0c04a988315deda19d5d to your computer and use it in GitHub Desktop.
import java.util.Arrays;
public class CheckDuplicatesUsingSorting {
public void hasDuplicatesUsingSorting(int [] arrA) {
Arrays.sort(arrA);
for (int i = 0; i < arrA.length-1; i++) {
if(arrA[i]==arrA[i+1]){
System.out.println("Array has duplicates : " + arrA[i]);
}
}
}
public static void main(String[] args) {
int a [] = {1, 6, 5, 2, 3, 3, 2};
new CheckDuplicatesUsingSorting().hasDuplicatesUsingSorting(a);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment