获取 Java 多维数组中的数组上限
为了获取多维数组的数组上限,我们使用 length() 方法。对于 2D 数组, length() 方法返回行数。我们可以使用 array_name[0].length 方法访问列数。
让我们看一个程序,用以获取 Java 多维数组中的数组上限
示例
public class Example {
public static void main(String args[]) {
String[][] str = new String[5][10];
System.out.println("1st dimension : " + str.length); // displays the number of rows
System.out.println("2nd dimension : " + str[0].length); // displays the number of columns
}
}输出
1st dimension : 5 2nd dimension : 10
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP