How to compare two object arrays in Java?

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

    In the example you've posted the arrays will actually contain Integer objects. In that case, Arrays.equals() is enough. However, if your arrays contain some objects of yours, you have to implement equals() in your class so that Arrays.equals() work

提交回复
热议问题