programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

Ranch Hand
Posts: 32
Hay all master, i am confused about array mutidimensional.
I wonder, how many object can construct for this array?

Thank you

Darryl Burke
Bartender
Posts: 5167
11
You first. How many do you think?

Ranch Hand
Posts: 32
I am not sure, honestly i don't know.
Once i think 3*9 = 12 is number of object, but i am wrong. It's number of element.

In my book that i read, it has 4(1+3) object.
I confused . Please explain to me.

Darryl Burke wrote:You first. How many do you think?

Matthew Brown
Bartender
Posts: 4568
9
Java doesn't really have multi-dimensional arrays. Instead, what it has is arrays-of-arrays. Given that, does that number make sense now?

Ranch Hand
Posts: 32
Matthew Brown wrote:Java doesn't really have multi-dimensional arrays. Instead, what it has is arrays-of-arrays. Given that, does that number make sense now?

Yes, of course Java builds multi-dimensional arrays from many one-dimensional arrays.
Just now, i get some reference , it says :

This actually allocates 6 objects: a one-dimensional array of 5 elements for each of the rows, and a one-dimensional array of ten elements, with each element pointing to the appropriate row array.
This case for array :

It is correct?

I am sorry for my bad english.
Thank you.

Campbell Ritchie
Marshal
Posts: 56529
172
Fandy Akhmad wrote: . . .
This actually allocates 6 objects: a one-dimensional array of 5 elements for each of the rows, and a one-dimensional array of ten elements, with each element pointing to the appropriate row array.
. . .
It is correct?
. . . .
No. 1 + 10 = 6???

That statement is incorrect in two respects.
• 1: It does not only allocate space, but also creates the objects.
• 2: When I was a little boy at school, 1 + 10 always made 11
• Please tell us where you found that statement.

 It is sorta covered in the JavaRanch Style Guide.