为了获得多维数组的数组上限,我们使用该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