When comparing arrays in Java, are there any differences between the following 2 statements?
Object[] array1, array2; array1.equals(array2); Arrays.equals(ar
array1.equals(array2) is the same as array1 == array2, i.e. is it the same array. As @alf points out it's not what most people expect.
array1.equals(array2)
array1 == array2
Arrays.equals(array1, array2) compares the contents of the arrays.
Arrays.equals(array1, array2)
Similarly array.toString() may not be very useful and you need to use Arrays.toString(array).
array.toString()
Arrays.toString(array)