Get Rows and Columns of 2D Array in Java



Following example helps to determine the rows and columns of a two-dimensional array with the use of arrayname.length.

Example

Following example helps to determine the upper bound of a two dimensional array with the use of arrayname.length. 

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

Output

The above code sample will produce the following result. 

Dimension 1: 2
Dimension 2: 5
Updated on: 2020-02-24T12:16:59+05:30

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements