.Tutorial # 10.

Two Dimensional Arrays



An array, is an indexed collection of one specific data types, that stores data values. Two dimensional arrays have more than one index, and can be thought of as an array of arrays. Arrays can have more than two dimensions, but once you get above two dimensions, it becomes harder to visually represent.

Declaration:
boolean[][] booleanValue;
int[][] numberArray;

Initialization:
booleanValue = new boolean[3][3];
numberArray = new int[100][100];

	booleanValue: (example)
		0	0	0
		0	1	1
		1	0	0

	numberArray: (example)
9 0 2 0 0 .... 8 2 7 7 5 .... 0 3 1 12 0 .... 6 5 5 3 9 .... 0 0 7 0 0 .... ... ... ... ... ...


To access a two dimensional array, put values inside the [] brackets, between 0 and size - 1. To access the 12 in numberArray, you would use numberArray[3][2], or numberArray[2][3], depending if you are referencing it row or column first.

// reset all the values to 0.
for (int i = 0; i < numberArray.length; i++) {
     for (int j = 0; j < numberArray[i].length; j++) {
          numberArray[i][j] = 0;
     }
}


Java Memory Model Links


From downtown:
PDF Format
PostScript Format

From Scarabourgh:
PostScript Format

sitemap