Google
 
Site navigation: [ Home | Theory | Java | Moodle courses | Resource wiki | About ]

Multi-dimensional arrays

2D arrays are not a mastery aspect but questions about them can be asked or algorithms set in the exam.

 

 

 

 

 

 

 

 

 

 

 

 

3D arrays are not part of the syllabus, we just thought you might be interested (yeah, right).

 

 

 

 

 

 

Arrays of more than one dimension
Arrays can also be multi-dimensional, a two-dimensional array might be useful to hold a set of positions in a board game, for example:

The elements of a 2D array are accessed by referring to the row then the column , thus board[1][2] contains the value 4 (rather than 3 which is in board[2][1]).

In the above example board could be a boolean or int type or even char using X's and O's. Arrays are defined using separate sets of square brackets for each dimension:

  int board [] [] = new int [3][3];

Arrays of larger dimensions than 2 are possible (but not so easy to draw!). A three dimensional array can be thought of as a cube, or represented in 2D as a series of grids.

A set of 2D arrays representing a cube

So the value 256 in the back of the cube would be referred to by cube[1][2][2] [row][col][plane].

Back to top

The chomp and more 2D arrays pages show example Classes which use 2D arrays.

 

Related: [ Java home | Previous: Array Operations | Next: Chomp ]

 


 
The site is partly financed by advertising revenue, partly by online teaching activities and partly by donations. If you or your organisation feel these resouces have been useful to you, please consider a donation, $9.95 is suggested. Please report any issues with the site, such as broken links, via the feedback page, thanks.

Questions or problems related to this web site should be addressed to Richard Jones who asserts his right to be identified as the author and owner of these materials - unless otherwise indicated. Please feel free to use the material presented here and to create links to it for non-commercial purposes; an acknowledgement of the source is required by the Creative Commons licence. Use of materials from this site is conditional upon your having read the additional terms of use on the about page and the Creative Commons Licence. View privacy policy.

Creative Commons License


This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. © 2001 - 2007 Richard Jones, PO BOX 246, Cambridge, New Zealand; This page was last modified: July 29, 200823, 2008