Question

Sorry if this question is a bit elementary, but I was wondering if there are names for the different arrays in a 2D array. For example, in:

int[][] array = new int[5][10];

What do I call the array with the length of 5? And what about the arrays with the length of 10? I was thinking something like the "primary array" and "secondary array" since the secondary arrays are stored in the primary array...

Any thoughts?

Was it helpful?

Solution

When looking at a multidimensional array (an array of arrays), the first length is the amount of rows there are. The second length is the amount of columns. So typically, say if running through a for loop, you could refer to them as such.

An example of a multidimensional array int [][] arr = new int[2][3] could look like:

[1, 2, 3] [4, 5, 6]

So there are [2] rows, of [3] columns.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top