Kishor Joshi

Ranch Hand

Posts: 674

Chan Ag

Rancher

Posts: 1090

14

posted 3 years ago

In Java we don't have multi-dimensional arrays. What we have is arrays of things. Things can be primitives or objects.

An array is a valid object and hence you can have arrays of arrays.

What that means is

is an array of 5 elements containing 5 ints.

is an array of 5 elements containing 5 String(s).

is an array of size 2 containing two Employee objects.

is not a two dimensional array.

It is an array of size 3 containing three arrays. These three arrays are of type int. The first array is of size 2, the second one is of size 3 and the third one is of size 4. So a[0] is the first element, i.e the first array, i.e a[0] = {1,2}.

To get the size of an array we can use the length attribute. So for the a array, we can say that a.length = 3.

We can also say that a[0].length = 2. This is also a hint for your problem statement.

And a[0][1] = 2. Of course you already know that.

An array is a valid object and hence you can have arrays of arrays.

What that means is

is an array of 5 elements containing 5 ints.

is an array of 5 elements containing 5 String(s).

is an array of size 2 containing two Employee objects.

is not a two dimensional array.

It is an array of size 3 containing three arrays. These three arrays are of type int. The first array is of size 2, the second one is of size 3 and the third one is of size 4. So a[0] is the first element, i.e the first array, i.e a[0] = {1,2}.

To get the size of an array we can use the length attribute. So for the a array, we can say that a.length = 3.

We can also say that a[0].length = 2. This is also a hint for your problem statement.

And a[0][1] = 2. Of course you already know that.