如何在 Java 中获取二维数组的行数和列数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34698144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get rows and columns count of a 2D array in Java?
提问by Aishwarya R
For an array in Java, we can get the length
of the array with array_name.length
. Similarly, how would one get the number of rows and columns of a 2Darray?
对于 Java 中的数组,我们可以length
使用array_name.length
. 同样,如何获得二维数组的行数和列数?
采纳答案by Idos
Well you probably want array_name.length
for getting the count of the rows and array_name[0].length
for the columns. That is, if you defined your array like so:
好吧,您可能想要array_name.length
获取行数和array_name[0].length
列数。也就是说,如果您像这样定义数组:
T[][] array_name = new T[row][col];
array_name.length // row
array_name[0].length // col