How to compare two object arrays in Java?

后端 未结 6 911
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 19:46

I have two object arrays like so:

Object[] array1 = {0, 1, 2, 3};
Object[] array2 = {0, 1, 2, 3};

I would like to know if the arrays are eq

6条回答
  •  無奈伤痛
    2020-12-09 20:03

    java.util.Arrays.equals

       /**
         * Returns true if the two specified arrays of Objects are
         * equal to one another.  The two arrays are considered equal if
         * both arrays contain the same number of elements, and all corresponding
         * pairs of elements in the two arrays are equal.  Two objects e1
         * and e2 are considered equal if (e1==null ? e2==null
         * : e1.equals(e2)).  In other words, the two arrays are equal if
         * they contain the same elements in the same order.  Also, two array
         * references are considered equal if both are null.

    * * @param a one array to be tested for equality. * @param a2 the other array to be tested for equality. * @return true if the two arrays are equal. */ public static boolean equals(Object[] a, Object[] a2)

提交回复
热议问题