I wish to find unique points in a bunch of Point arrays (i.e. removing all the duplicates and seeing what is left).
Here is the code I have tried:
int numCount = 0;
for (int x = 0; x < ALLARRAYS.length; x++) {
for (final Point test : ALLARRAYS[x]) {
NUMBER: for (final Point[] numbers : ALLARRAYS) {
if (numbers == ALLARRAYS[x]) {
continue;
}
for (int i = 0; i < numbers.length; i++) {
if (test.equals(numbers[i])) {
break NUMBER;
} else {
if (i == numbers.length - 1) {
numCount++;
}
}
}
}
if (numCount == 10) {
System.out.println(x + "\tPoint: " + test.x + ", " + test.y + " is unique.");
}
numCount = 0;
}
System.out.println();
}
Basically, I have eleven arrays I want to check, therefore the numCount checks for 10 arrays to be confirmed. My approach was to cycle through each array, then cycle through all the points in that array, and then cycle through each point in every other array. If it sees a duplicate, it skips the whole number entirely.
My problem: I am getting false readings. I am not sure what is going on, but the program spits out points that already exist in other arrays.
My goal: Each array works as a whole. If one element is not satisfied, then the whole array is skipped. My end result should be 11 smaller-in-size arrays that are all unique so that a method can check through the elements of each set and determine that they are all unique.
NOTE: The arrays are all unique now, they are just ridiculously huge. I am looking for a way to truncate it by creating this mini-program to eliminate duplicates.
My question: Can someone please help me out?
test == numbers[i]. Point is a class, comparing it using the==operator is only going to return true iftestandnumbers[i]have references that are the same. Try usingtest.equals(numbers[i])instead?Pointto itself.