It was really hard to remember.
int numberOfColumns = arr.length; int numberOfRows = arr[0].length;
Let's understand why this is so, and how we can find out when we are asked a problem with arrays. From the code below you can see that rows = 4 and columns = 3:
int[][] arr = { {1, 1, 1, 1}, {2, 2, 2, 2}, {3, 3, 3, 3} };
arr has several arrays, and these arrays can be arranged vertically to get the number of columns. To get the number of rows, we need to access the first array and consider its length. In this case, we get access to [1, 1, 1, 1] and, thus, the number of rows = 4. When you are asked a problem, when you do not see the array, you can visualize the array as a rectangle with n X m dimensions and we conclude that we can get the number of rows by accessing the first array, and then its length. Another ( arr.length ) for columns.
gocode Jan 23 '19 at 16:00 2019-01-23 16:00
source share