Unit 4 · Data Collections
2D Array Basics
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
What 2d array basics covers
A 2D array in Java is an array of arrays, stored in row-major order, so grid[r][c] means row r, column c. The number of rows is grid.length and the number of columns in a row is grid[r].length. Creating one with new int[3][4] gives three rows of four columns, all filled with the type default. Initializer lists let you write the grid out literally, with each inner set of braces forming one row.
Where students lose points
Reversing the two indexes is the defining mistake, and it either reads the wrong value or throws when the grid is not square. Students also use grid.length as the column count, which only happens to work for square grids, and they misread new int[3][4] as four rows of three.
How it shows up on the AP exam
Unit 4 data collections. 2D arrays appear as a full FRQ on a regular basis, and index order is the first thing that has to be right.
For practice use only.
2D Array Basics MCQ Practice
AP CSA 2D array basics practice: row-major indexing, declaring and initializing grids, row and column counts, and default element values.
Answered 0 of 15
Choose one answer.
Which option matches the complete output produced by this segment?
public class GridArrayBasicsContext
{
public static void runExample()
{
int[][] g = new int[2][3];
g[1][2] = 5;
System.out.print(g.length + " " + g[0].length
+ " " + g[1][2]);
}
public static void main(String[] args)
{
runExample();
}
}