I have an array, and am looking for duplicates.
duplicates = false;
for(j = 0; j < zipcodeList.length; j++){
for(k = 0; k < zipcodeList.length; k++
This program will print all duplicates value from array.
public static void main(String[] args) {
int[] array = new int[] { -1, 3, 4, 4,4,3, 9,-1, 5,5,5, 5 };
Arrays.sort(array);
boolean isMatched = false;
int lstMatch =-1;
for(int i = 0; i < array.length; i++) {
try {
if(array[i] == array[i+1]) {
isMatched = true;
lstMatch = array[i+1];
}
else if(isMatched) {
System.out.println(lstMatch);
isMatched = false;
lstMatch = -1;
}
}catch(Exception ex) {
//TODO NA
}
}
if(isMatched) {
System.out.println(lstMatch);
}
}
}