How to compare two object arrays in Java?

后端 未结 6 930
爱一瞬间的悲伤
爱一瞬间的悲伤 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:05

    To compare arrays, I would use the Arrays.equals method:

    if (Arrays.equals(array1, array2))
    {    
      // array1 and array2 contain the same elements in the same order
    }
    

提交回复
热议问题