Glossary
"rectangular" arrays
A specific type of 2D array where all inner arrays (rows) have the exact same number of elements (columns), forming a consistent, uniform grid shape.
Example:
An int[5][3]
array is a "rectangular" array because every one of its 5 rows will contain exactly 3 integer elements.
0-indexed language
A programming language, like Java, where the first element in a sequence or array is located at index 0, the second at index 1, and so on.
Example:
Because Java is a 0-indexed language, an array with 5 elements will have valid indices ranging from 0 to 4.
1D arrays
A linear data structure that stores a collection of elements of the same type in a single sequence or row.
Example:
A shopping list containing items like 'milk', 'eggs', and 'bread' could be stored in a 1D array of Strings.
2D Array
A data structure in Java that organizes data into a grid-like format, essentially an array where each element is itself a one-dimensional array.
Example:
A chessboard can be represented as a Piece[][] board
where board[0][0]
refers to the piece at the top-left square, demonstrating a 2D Array.
2D Arrays
A data structure used to organize data into a grid-like format, allowing for the storage and manipulation of elements in rows and columns.
Example:
A spreadsheet can be conceptually represented as a 2D array of cells, where each cell holds a piece of data.
ArrayIndexOutOfBoundsException
A runtime error that occurs when a program attempts to access an array element using an index that is outside the valid range of indices for that array.
Example:
If you have an array int[] numbers = new int[5];
and try to access numbers[5]
, it will result in an ArrayIndexOutOfBoundsException.
ArrayIndexOutOfBoundsException
A runtime error that occurs when a program attempts to access an array element using an index that is outside the valid range of indices for that array.
Example:
If you try to access myGrid[5][0]
when myGrid
is declared as new int[3][4]
, it will result in an ArrayIndexOutOfBoundsException.
Column-major order
A method for traversing a 2D array by processing all elements in the first column, then all elements in the second column, and so on, from top to bottom.
Example:
Imagine a robot scanning a barcode by moving vertically down each bar before moving to the next bar; this process mimics column-major order traversal.
Enhanced for loops
A simplified loop construct in Java, also known as a for-each loop, used to iterate over all elements in an array or collection without explicitly managing indices.
Example:
To print every card in a String[] hand
, you could use for (String card : hand) { System.out.println(card); }
, which is an enhanced for loop.
Nested Array
A conceptual way to view a 2D array, where the outer array contains other arrays as its elements, forming a hierarchical structure.
Example:
Consider a school building where each floor is an array of classrooms, and the entire building is a nested array of floors.
Rectangular Array
A specific type of 2D array where all the inner arrays (rows) have the same length, creating a uniform grid shape.
Example:
A seating chart for a theater with 10 rows and each row having exactly 15 seats would be a rectangular array.
Row-major order
A common method for traversing a 2D array by processing all elements in the first row, then all elements in the second row, and so on, from left to right.
Example:
When filling out a multiple-choice answer sheet, you typically complete all bubbles for question 1, then question 2, and so on, which is analogous to row-major order traversal.
double-index notation
The method of using two bracketed numbers, `[row][column]`, to specify the exact location of an element within a 2D array.
Example:
To retrieve the value in the third row and fourth column of myMatrix
, you would use double-index notation like myMatrix[2][3]
.
firstDimension
When declaring a 2D array as `type[firstDimension][secondDimension]`, this refers to the number of rows in the array.
Example:
In char[][] gameBoard = new char[3][3];
, the firstDimension is 3, indicating three rows.
grid, table, or matrix
Visual representations of a rectangular 2D array, where data is organized into rows and columns, similar to a spreadsheet or a mathematical matrix.
Example:
A game of Tic-Tac-Toe can be easily visualized as a 3x3 grid where each cell holds an 'X', 'O', or is empty.
indices
Numerical positions used to identify and access individual elements within an array or 2D array, starting from zero.
Example:
To access the element 'A' in a 2D array char[][] letters = {{'A','B'},{'C','D'}}
, you would use the indices letters[0][0]
.
inner array
In the memory representation of a 2D array, these are the arrays contained within the outer array, each representing a row of elements.
Example:
In int[][] data = {{1,2}, {3,4}};
, {1,2}
and {3,4}
are the inner arrays.
length (vs. size)
`length` is a public field used to determine the number of elements in an array, while `size()` is a method used to get the number of elements in an `ArrayList`.
Example:
To find the number of rows in a 2D array grid
, you would use grid.**length**
, not grid.size()
.
nested array
A conceptual representation of a 2D array where the outer array contains other arrays as its individual elements, forming a structure of arrays within an array.
Example:
In Java, int[][] matrix
is fundamentally a nested array, where matrix[0]
refers to the first inner array (row).
outer array
In the memory representation of a 2D array, this is the primary array that holds references to the individual inner arrays, which represent the rows.
Example:
For String[][] board = new String[8][8];
, the board
variable itself refers to the outer array that contains 8 references to String arrays.
secondDimension
When declaring a 2D array as `type[firstDimension][secondDimension]`, this refers to the number of columns in the array.
Example:
In char[][] gameBoard = new char[3][3];
, the secondDimension is 3, indicating three columns.
traverse
The process of systematically visiting each element within a data structure, such as a 2D array, typically by iterating through its rows and columns.
Example:
To calculate the sum of all numbers in a grid, you would traverse the 2D array, adding each element to a running total.