When comparing arrays in Java, are there any differences between the following 2 statements?
Object[] array1, array2;
array1.equals(array2);
Arrays.equals(ar
The equals()
of arrays is inherited from Object
, so it does not look at the contents of the arrrays, it only considers each array equal to itself.
The Arrays.equals()
methods do compare the arrays' contents. There's overloads for all primitive types, and the one for objects uses the objects' own equals()
methods.