Forums Register Login

multidimensional arrays, references and values. Need help understanding...

+Pie Number of slices to send: Send
I'm pining for more love from the concept of arrays of arrays. But I can't hug 'em like I want to.
I'm SCJP 1.3 and I'm studying for the 1.4 Upgrade. I bought Kathy and Bert's most excellent guide and Chapter 1 enlightened me to just how much I don't know about arrays of arrays, especially complex multidimensional arrays pass the simplest two dimensional array (I mean come on, "On The Job" who uses arrays of arrays as complex as four deep?)
While I understand the "rules" of arrays of arrays and assignments, I'm having trouble visualizing the dimensions and values of multidimensional arrays. I got the basics down:
Basic two-dimensional example:

I'm translating this as an "array of seven null int arrays" So...

This compiles and the output is as expected:
(In fact any legal call to iArr would be 0 but that's given.)
For more fun, and about the point I start getting lost:

I see this as an "array of seven int arrays, each seven in length, each index initialized to zero (default)" Is this correct?
For more complex fun:

Whew. Okay, I'm lost. I need help visualizing this multi dimensional array. (See Kathy and Bert's book for an example almost identical in nature. Which KUDOS are in order. What a fantastic book! I'm learning a lot more this time around studying for the SCJP than the first time!)
[ May 10, 2003: Message edited by: Timothy Stone ]
+Pie Number of slices to send: Send
 

Originally posted by Timothy Stone:

For more fun, and about the point I start getting lost:

I see this as an "array of seven int arrays, each seven in length, each index initialized to zero (default)" Is this correct?


I think that is correct.

Originally posted by Timothy Stone:

For more complex fun:

Whew. Okay, I'm lost. I need help visualizing this multi dimensional array.
[ May 10, 2003: Message edited by: Timothy Stone ]


So in this case the way I see it is you have an array of size 2 each index pointing to an array of size 3 from which each index points to an array of size 1 and the index of that pointing to an array of size 4 where each index contains an int.
Hope that helps.
+Pie Number of slices to send: Send
If you're having trouble "visualizing" things, draw a picture!
For a simple array, you might draw something like this:

For a more complicated array, you might draw this:

For something as complex as this, you're going to have a much more elaborate picture:

I realize that my ASCII art isn't great for complex drawings but, hopefully, you get the idea. Whenever I start to get confused by data objects, I always draw a picture - it just helps me "visualize" what I'm doing. I hope it helps you.
Corey
+Pie Number of slices to send: Send
Here's some test code I wrote to help me vizualize:

I see now that the final [n] denotes the size of the last array.
I could play with endlessly. And by playing I've reinforced Kathy and Bert's notes on legal references and assignments.
Thank you Daimen for the hint. And Corey for the most excellent ASCII art (I had just finished my own drawing in <plug-bell /> OmniGraffle duping exactly your art. Thank you all.
[ February 08, 2004: Message edited by: Timothy Stone ]
[ February 15, 2004: Message edited by: Timothy Stone ]
Stop it! You're embarassing me! And you are embarrassing this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 722 times.
Similar Threads
multidimensional arrrays
multidimensional array
HELP!! Multidimensional Array Migraine
Multidimensional Arrays
Constructing multidimensional arrays
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:24:05.