0 votes
1 view
in Java by (5.5k points)

When comparing arrays in Java, are there any differences between the following 2 statements?

array1.equals(array2);

Arrays.equals(array1, array2);

And if so, what are they?

1 Answer

0 votes
by (33.2k points)
array1.equals(array2) is the equivalent as array1 == array2, i.e. is it the same array. it's not what most utmost people expect.

Arrays.equals(array1, array2) connects the contents of the arrays.

Similarly, array.toString() may not be quite useful and you need to use Arrays.toString(array).
...