I need to be able to search a two dimensional java array for duplicate values, and then report which location has the duplicate value. How would I go about doing this?
I thought if I would subtract 1 from my col and row, that it would work in a double for loop, but I get an exception thrown because you cant have a -1 in an array...
How would I search my array for a duplicate value?
Here is my code:
boolean dupval = false;
for(int row = 0; row < 3; row++)
int count = row;
for(int col = 0; col < 3; col++)
String newVal = myArray[col][row].getText();
int val = Integer.parseInt(newVal);
previousVal = myArray[col-1][row-1].getText();
prevInt = Integer.parseInt(previousVal);
if(val == prevInt)
//report a duplicate error
dupval = true;
Thanks in advance,