I am trying to make it so if there are any duplicates in the array, it turns true and if there is not it turns false. But, no matter what I do the if statement always turns in into false, even if there isn't a duplicate. This has to be done as a boolean.
int array[] = {10, 20, 30, 10, 40, 50};
public boolean hasDuplicates2() {
for (int i = 0; i <= array.length; i++) {
for (int i2 = 1; i2 <= array.length - 1; i2++) {
if (array[i] != array[i2]) {
return false;
}
}
}
return true;
}