What is the difference between using `equals` and `Arrays.equals` when comparing arrays in Java, and how do they behave differently?

Here’s the preferred method when you want to check if two arrays contain the same elements in the same order:

Arrays.equals(array1, array2);

This method iterates through both arrays and checks each element using their equals() method.

:heavy_check_mark: Works perfectly for:

  • One-dimensional arrays (like int[], String[], or Object[])

  • Content-based comparison

:no_entry_sign: But: It does not work correctly for multi-dimensional arrays like String[][].