Java: Testing array equality

if (Arrays.equals(arr1, arr2)) {
    ...
}

Note that this performs a shalow comparison, i.e. it checks

This is not suitable for multidimensional arrays.

Multidimensional arrays

if (Arrays.deepEquals(arr1, arr2)) {
    ...
}

This method recurses on the arrays and compares the actual elements.

Comments

Be the first to comment!