Java Examples - Get array length
In this paper, we will introduce how to use the length property of the array to get the length of the array.
The following example, we define a two-dimensional array, and get the length of the array:
/* author by w3cschool.cc 文件名:Main.java */ public class Main { public static void main(String args[]) { String[][] data = new String[2][5]; System.out.println("第一维数组长度: " + data.length); System.out.println("第二维数组长度: " + data[0].length); } }
The above code is run output is:
第一维数组长度: 2 第二维数组长度: 5