Reputation: 23
So I am trying to use a for-loop in my Java program but I can't figure out how to return true if two values match. I am using a List<int[]>
and a int[]
. Here is my code:
public class ClickableObject
{
List<int[]> objectCoords;
public ClickableObject(List<int[]> gridSpaces)
{
objectCoords = gridSpaces;
}
public boolean isClicked(int[] clickCoords)
{
// This loop is not working
for(int i = 0; i < objectCoords.size(); i++)
{
if(clickCoords == objectCoords.get(i))
return true;
}
return false;
}
}
The method isClicked(int[] clickCoords)
takes in a two-integer array, which has the x and y coordinates of the click. It should run it through and find if an int[]
in objectCoords
matches the clickCoords.
Upvotes: 2
Views: 42
Reputation: 631
You should use
Arrays.deepEquals(clickCoords, objectCoords.get(i))
Upvotes: 1