Java Examples - Get Array Length

Java 实例Java Examples

In this article, we will introduce how to use the length property of an array to get the length of the array.

In the following example, we define a two-dimensional array and get the length of the array:

Main.java file

public class Main { public static void main(String args[]) { String[][] data = new String[2][5]; System.out.println("Length of the first dimension array:" + data.length); System.out.println("Length of the second dimension array:" + data[0].length); } }

The output of the above code is:

第一维数组长度: 2 
第二维数组长度: 5

Java 实例Java Examples

Other Extensions