Easy Tutorial
❮ Date Time Am Pm Java If Else Switch ❯

Java Example - Getting Array Length

Java Examples

In this article, we will show you 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 retrieve its length:

Main.java File

public class Main {
   public static void main(String args[]) {
      String[][] data = new String[2][5];
      System.out.println("First dimension length: " + data.length);
      System.out.println("Second dimension length: " + data[0].length);
   }
}

The output of the above code is:

First dimension length: 2
Second dimension length: 5

Java Examples

❮ Date Time Am Pm Java If Else Switch ❯