How can I find if my ArrayList of int[] contains an int[]

前端 未结 4 1709
广开言路
广开言路 2021-01-23 09:58

I have an ArrayList containing int[].

Assuming Arrays.equals(int[], (a value in the arrayList)) = true

why when I do

4条回答
  •  臣服心动
    2021-01-23 10:15

    A list of arrays stores only the references to the arrays, not their content, therefore contains() is only able to say, if the list contains the exact reference to the array you input. It doesn't evaluate the contents of the array.

    If you need to check, if the list contains an array with specific values, you will have to iterate over the list and use Arrays.equals(arr1, arr2).

提交回复
热议问题