My main problem is that the contains()
method on my ArrayList
returns always false
, and I am not sure why.
I have created an ArrayList<Position>
called allValidPositions
, which contains many instances of my custom class called Position
.
When I try to find a specific Position
element in the ArrayList
, it always returns false
.
// The parameters represent X and Y coordinates
Position positionToCheck = new Position(0, 0);
if (allValidPositions.contains(positionToCheck) {
System.out.println("Found");
} else {
System.out.println("Not found");
}
It always prints Not found
although I know that there is a Position that should be the same object (the fields and values in the objects are the same).