aspose file tools*
The moose likes Java in General and the fly likes Multidimensional Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Multidimensional Arrays" Watch "Multidimensional Arrays" New topic
Author

Multidimensional Arrays

Aruna Balasuriya
Ranch Hand

Joined: Nov 14, 2009
Posts: 44
Why following code results a runtime exception

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

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].


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multidimensional Arrays