<qhelp>

<overview>

The `equals` and `hashCode` methods on arrays only consider object identity, not array contents, which is unlikely to be what is intended.

</overview> <recommendation>

To compare the lengths of the arrays and the corresponding pairs of elements in the arrays, use one of the comparison methods from `java.util.Arrays`:

- The method `Arrays.equals` performs a shallow comparison. That is, array elements are compared using `equals`.
- The method `Arrays.deepEquals` performs a deep comparison, which is appropriate for comparisons of nested arrays.

Similarly, `Arrays.hashCode` and `Arrays.deepHashCode` can be used to compute shallow and deep hash codes based on the hash codes of individual array elements.

</recommendation> <example>

In the following example, the two arrays are first compared using the `Object.equals` method. Because this checks only reference equality and the two arrays are different objects, `Object.equals` returns `false`. The two arrays are then compared using the `Arrays.equals` method. Because this compares the length and contents of the arrays, `Arrays.equals` returns `true`.

</example> <references>
- Java API Documentation: Arrays.equals, Arrays.deepEquals, Object.equals, Arrays.hashCode, Arrays.deepHashCode, Object.hashCode.
</references> </qhelp>