java program to find duplicates in an array code example
Example 1: java array check duplicates
duplicates = false;
for(i = 0; i < zipcodeList.length; i++) {
for(j = i + 1; k < zipcodeList.length; j++) {
if(j != i && zipcodeList[j] == zipcodeList[i]) {
duplicates = true;
}
}
}
Example 2: find repeated elements in array java
for (String name : names) {
if (set.add(name) == false) {
// your duplicate element
}
}