How do I check if an ArrayList<int[]>
contains a given array [x, y]? I have found the same question in c#, but can't find any answers for java.
At the moment I am using myList.contains(myArray)
but it is always evaluating to false, I assume for similar reasons as in C#. The solution in C# is to use LINQ, which does not exist in java.
Is there another way I can do this or will I have to write my own subroutine to pull out the values of each list element and compare them manually?
Edit: I've written my own subroutine to do this which works (assuming each array has two elements), but a more elegant solution would be appreciated
private boolean contains(List<int[]> list, int[] array) {
for (int[] listItem : list) {
if (listItem[0] == array[0] &&
listItem[1] == array[1]) {
return true;
}
}
return false;