Java ArrayList contains method doesn't work

Viewed 2886

So when I run this program it shows that the ArrayList "test" doesn't contain the array [5,6] inside the variable "position".When I checked the output, it is clearly in there and i see that "test" does contain that element.


Output:

[5, 6] [5, 6] false

Code:

package arraylisttest;

import java.util.ArrayList;
import java.util.Arrays;

public class ArrayListTest {
    public static void main(String[] args) {
        int[] position = { 5, 6 };
        ArrayList<int[]> test = new ArrayList<>();

        test.add(new int[] {50, 2});
        test.add(new int[] {0, 7});
        test.add(new int[] {5, 6});
        test.add(new int[] {2, 1});

        System.out.println(Arrays.toString(position));
        System.out.println(Arrays.toString(test.get(2)));
        System.out.println(test.contains(position));
    }
}
3 Answers
Related