是否可以检查两个数组是否相等 [英] Is it possible to check if two arrays are not equal

查看:85
本文介绍了是否可以检查两个数组是否相等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以做一个事实:

I'm aware of the fact that I could just do a:

while(Arrays.equals(array1, array2))

,然后只需编写else语句中所需的代码即可.

and then just write the code needed in the else statement.

还有其他方法可以检查它们是否相等?

Is there any other way to check if they are not equal?

推荐答案

怎么了

if(!Arrays.equals(array1,array2))

if( !Arrays.equals(array1, array2) )

array1.equals(array2)array1 == array2相同, 即是同一数组吗?这不是大多数人期望的.

array1.equals(array2) is the same as array1 == array2, i.e. is it the same array. And it's not what most people expect.

Arrays.equals(array1, array2)比较数组的内容.

这篇关于是否可以检查两个数组是否相等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆