File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multidimensional Arrays

 
Aruna Balasuriya
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why following code results a runtime exception

 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's check out what each array contains. Initially:
a1 = {null}
a2 = {{null}, {null}}
a3 = {{{null, null, null}, {null, null, null}, {null, null, null}}, {{null, null, null}, {null, null, null}, {null, null, null}}, {{null, null, null}, {null, null, null}, {null, null, null}}}

a1 then becomes {A}
a2 becomes {{A}, {A}}
a3 becomes {{{A}, {A}}, {{A}, {A}}, {{A}, {A}}}

a3 is now no longer an A[3][3][3] but an A[3][2][1]. As such, there is no a3[2][2]. The highest indexes you can get is a3[2][1][0].
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic