equals vs Arrays.equals in Java

前端 未结 8 1409
走了就别回头了
走了就别回头了 2020-11-21 23:29

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

Object[] array1, array2;
array1.equals(array2);
Arrays.equals(ar         


        
8条回答
  •  忘了有多久
    2020-11-22 00:10

    The Arrays.equals(array1, array2) :

    check if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal.

    The array1.equals(array2) :

    compare the object to another object and return true only if the reference of the two object are equal as in the Object.equals()

提交回复
热议问题