java中比较二维整数数组的最佳方法
我想知道比较二维整数数组的最佳、最快和最简单的方法是什么。 数组的长度是相同的。 (其中一个数组是临时数组)
I would like to know what is the best, fastest and easiest way to compare between 2-dimension arrays of integer.
the length of arrays is the same. (one of the array's is temporary array)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
伊丹写道:
如果您想检查所有元素的
a[i][j]
是否等于b[i][j]
,只需使用Arrays.deepEquals(a, b)。Edan wrote:
If you want to check that
a[i][j]
equalsb[i][j]
for all elements, just useArrays.deepEquals(a, b)
.看看
java.util.Arrays
;它有许多您应该熟悉的数组实用程序。
来自 API:
请注意,在 Java 中,
int[][]
是Object[]
的子类型。 Java 并没有真正的二维数组。它有数组的数组。此处显示了嵌套数组的
equals
和deepEquals
之间的区别(请注意,默认情况下 Java 使用零作为元素初始化int
数组)。相关问题
Arrays.equals() 对于二维数组返回
false
Look at
java.util.Arrays
; it has many array utilities that you should familiarize yourself with.From the API:
Note that in Java,
int[][]
is a subtype ofObject[]
. Java doesn't really have true two dimensional arrays. It has array of arrays.The difference between
equals
anddeepEquals
for nested arrays is shown here (note that by default Java initializesint
arrays with zeroes as elements).Related questions
Arrays.equals()
returnsfalse
for two dimensional arrays