• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Timothy Stone
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
What are you doing in my house? Get 'em tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic