I want to add an int[]
to an ArrayList if it doesn't already have that int[]
, but for some reason, it's not working. In this case, arrlist is the ArrayList<int[]>
and arr is the int[]
. This code is in a for loop where arr is defined in the loop, so the values in arr changes. Even though I printed out arrlist and it had arr, the code would always say that arrlist didn't contain arr. Is there another way to check if an ArrayList contains an int[]
?
int n = scan.nextInt();
ArrayList<int[]> arrlist = new ArrayList<>();
int[][] coordinates = new int[n][2];
boolean[] isTrue = new boolean[n];
for (int j = 0; j < n; j++) {
int[] arr = new int[2];
arr[0] = coordinates[j][0];
arr[1] = coordinates[j][1];
if (arrlist.contains(arr)) {
isTrue[j] = true;
} else {
arrlist.add(arr);
}
}