how to get length of 2d array java

www.la‮uttu‬ri.com
how to get length of 2d array java

To get the length of a two-dimensional (2D) array in Java, you can use the length field of the array, which holds the number of rows in the array. To get the number of columns in a row, you can use the length field of one of the rows.

Here's an example of how you can get the length of a 2D array in Java:

int[][] numbers = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int rows = numbers.length;
int columns = numbers[0].length;

In this example, the numbers array is a 2D array containing three rows and three columns. The rows variable holds the number of rows in the array, and the columns variable holds the number of columns in a row.

You can also use a loop to iterate over the rows and columns of the array and perform operations on the elements.

Created Time:2017-11-01 20:42:55  Author:lautturi