If you have multi-dimensional arrays (e.g., Object[][]
), you’ll want to use:
Arrays.deepEquals(array1, array2);
Why? Because Arrays.equals()
will just compare nested array references not the contents inside them. deepEquals()
goes the extra mile to recursively compare elements in nested arrays.
Use this when you’re dealing with nested arrays. You want a deep comparison of all levels