2D Array Creation and Access - AP Computer Science A
Card 1 of 30
What is a 2D array?
What is a 2D array?
Tap to reveal answer
A data structure storing elements in a grid with rows and columns. Elements arranged in matrix format with row and column indices.
A data structure storing elements in a grid with rows and columns. Elements arranged in matrix format with row and column indices.
← Didn't Know|Knew It →
How do you declare a 2D array in Java?
How do you declare a 2D array in Java?
Tap to reveal answer
int[][] arrayName;. Declaration syntax uses double brackets for 2D array type.
int[][] arrayName;. Declaration syntax uses double brackets for 2D array type.
← Didn't Know|Knew It →
How do you initialize a 3x3 int 2D array in Java?
How do you initialize a 3x3 int 2D array in Java?
Tap to reveal answer
int[][] array = new int[3][3];. Creates a 3x3 matrix with new keyword and size specification.
int[][] array = new int[3][3];. Creates a 3x3 matrix with new keyword and size specification.
← Didn't Know|Knew It →
Which method accesses the element at row 2, column 1?
Which method accesses the element at row 2, column 1?
Tap to reveal answer
array[2][1];. First index specifies row, second index specifies column.
array[2][1];. First index specifies row, second index specifies column.
← Didn't Know|Knew It →
What is the index of the first row and first column in a 2D array?
What is the index of the first row and first column in a 2D array?
Tap to reveal answer
[0][0]. Arrays use zero-based indexing for both dimensions.
[0][0]. Arrays use zero-based indexing for both dimensions.
← Didn't Know|Knew It →
How many elements are in a 2D array of size 4x5?
How many elements are in a 2D array of size 4x5?
Tap to reveal answer
20 elements. Total elements equals rows multiplied by columns: $4 \times 5 = 20$.
20 elements. Total elements equals rows multiplied by columns: $4 \times 5 = 20$.
← Didn't Know|Knew It →
How do you update the element at row 1, column 2 to 10?
How do you update the element at row 1, column 2 to 10?
Tap to reveal answer
array[1][2] = 10;. Assignment syntax uses array notation with row and column indices.
array[1][2] = 10;. Assignment syntax uses array notation with row and column indices.
← Didn't Know|Knew It →
What is the default value of elements in a new int 2D array?
What is the default value of elements in a new int 2D array?
Tap to reveal answer
- Java initializes numeric array elements to zero by default.
- Java initializes numeric array elements to zero by default.
← Didn't Know|Knew It →
What is the syntax to iterate over all elements in a 2D array?
What is the syntax to iterate over all elements in a 2D array?
Tap to reveal answer
for (int i = 0; i < array.length; i++) for (int j = 0; j < array[i].length; j++). Nested loops traverse rows first, then columns within each row.
for (int i = 0; i < array.length; i++) for (int j = 0; j < array[i].length; j++). Nested loops traverse rows first, then columns within each row.
← Didn't Know|Knew It →
What is the length of a 2D array row array[0]?
What is the length of a 2D array row array[0]?
Tap to reveal answer
array[0].length. Returns number of columns in the specified row.
array[0].length. Returns number of columns in the specified row.
← Didn't Know|Knew It →
How do you define a 2D array with specific values?
How do you define a 2D array with specific values?
Tap to reveal answer
int[][] array = {{1, 2}, {3, 4}};. Initializer list syntax creates array with literal values.
int[][] array = {{1, 2}, {3, 4}};. Initializer list syntax creates array with literal values.
← Didn't Know|Knew It →
Identify the method to get the number of rows in a 2D array.
Identify the method to get the number of rows in a 2D array.
Tap to reveal answer
array.length. Length property returns the number of rows in the array.
array.length. Length property returns the number of rows in the array.
← Didn't Know|Knew It →
Identify the method to get the number of columns in the first row.
Identify the method to get the number of columns in the first row.
Tap to reveal answer
array[0].length. Accesses the length property of the first row array.
array[0].length. Accesses the length property of the first row array.
← Didn't Know|Knew It →
Which keyword is used to create a new 2D array in Java?
Which keyword is used to create a new 2D array in Java?
Tap to reveal answer
new. Required keyword for dynamic memory allocation in Java.
new. Required keyword for dynamic memory allocation in Java.
← Didn't Know|Knew It →
What is a jagged array?
What is a jagged array?
Tap to reveal answer
A 2D array where rows have different lengths. Each row can have different number of columns.
A 2D array where rows have different lengths. Each row can have different number of columns.
← Didn't Know|Knew It →
How do you access the last element of the last row in a 2D array?
How do you access the last element of the last row in a 2D array?
Tap to reveal answer
array[array.length - 1][array[array.length - 1].length - 1]. Uses length properties to calculate final position indices.
array[array.length - 1][array[array.length - 1].length - 1]. Uses length properties to calculate final position indices.
← Didn't Know|Knew It →
How do you check if a 2D array element is zero?
How do you check if a 2D array element is zero?
Tap to reveal answer
if (array[i][j] == 0). Conditional statement compares element value to zero.
if (array[i][j] == 0). Conditional statement compares element value to zero.
← Didn't Know|Knew It →
What is the purpose of nested loops in 2D arrays?
What is the purpose of nested loops in 2D arrays?
Tap to reveal answer
To iterate through rows and columns. Outer loop handles rows, inner loop handles columns.
To iterate through rows and columns. Outer loop handles rows, inner loop handles columns.
← Didn't Know|Knew It →
How do you declare a char 2D array?
How do you declare a char 2D array?
Tap to reveal answer
char[][] array;. Declaration syntax for character data type in 2D format.
char[][] array;. Declaration syntax for character data type in 2D format.
← Didn't Know|Knew It →
What is the syntax to assign 'A' to the first element of a 2D char array?
What is the syntax to assign 'A' to the first element of a 2D char array?
Tap to reveal answer
array[0][0] = 'A';. Assignment uses array indexing with character literal value.
array[0][0] = 'A';. Assignment uses array indexing with character literal value.
← Didn't Know|Knew It →
How do you initialize a 2D array with 2 rows and 3 columns?
How do you initialize a 2D array with 2 rows and 3 columns?
Tap to reveal answer
int[][] array = new int[2][3];. Specifies exact dimensions during array creation.
int[][] array = new int[2][3];. Specifies exact dimensions during array creation.
← Didn't Know|Knew It →
How do you access the second column of the first row in a 2D array?
How do you access the second column of the first row in a 2D array?
Tap to reveal answer
array[0][1]. Second index (1) selects the second column position.
array[0][1]. Second index (1) selects the second column position.
← Didn't Know|Knew It →
How do you initialize a 2D array with specific String values?
How do you initialize a 2D array with specific String values?
Tap to reveal answer
String[][] array = {{"a", "b"}, {"c", "d"}};. Initializer syntax with String literals in nested structure.
String[][] array = {{"a", "b"}, {"c", "d"}};. Initializer syntax with String literals in nested structure.
← Didn't Know|Knew It →
What is the result of accessing out-of-bounds index in a 2D array?
What is the result of accessing out-of-bounds index in a 2D array?
Tap to reveal answer
ArrayIndexOutOfBoundsException. Runtime exception thrown when index exceeds array bounds.
ArrayIndexOutOfBoundsException. Runtime exception thrown when index exceeds array bounds.
← Didn't Know|Knew It →
What is an example of a rectangular 2D array?
What is an example of a rectangular 2D array?
Tap to reveal answer
int[][] array = new int[3][3];. All rows have same length, forming regular matrix shape.
int[][] array = new int[3][3];. All rows have same length, forming regular matrix shape.
← Didn't Know|Knew It →
What will array.length return for a 4x6 2D array?
What will array.length return for a 4x6 2D array?
Tap to reveal answer
- Length property returns number of rows in the array.
- Length property returns number of rows in the array.
← Didn't Know|Knew It →
What is an example of initializing a jagged 2D array?
What is an example of initializing a jagged 2D array?
Tap to reveal answer
int[][] array = { {1, 2}, {3, 4, 5} };. Different row lengths create irregular array structure.
int[][] array = { {1, 2}, {3, 4, 5} };. Different row lengths create irregular array structure.
← Didn't Know|Knew It →
What is the default value of a boolean 2D array?
What is the default value of a boolean 2D array?
Tap to reveal answer
false. Java initializes boolean array elements to false by default.
false. Java initializes boolean array elements to false by default.
← Didn't Know|Knew It →
How do you declare a 2D array reference of any type?
How do you declare a 2D array reference of any type?
Tap to reveal answer
Type[][] array;. Generic declaration syntax for any reference type.
Type[][] array;. Generic declaration syntax for any reference type.
← Didn't Know|Knew It →
How do you create a 2D array with 5 rows and variable columns?
How do you create a 2D array with 5 rows and variable columns?
Tap to reveal answer
int[][] array = new int[5][];. Creates row structure without specifying column dimensions.
int[][] array = new int[5][];. Creates row structure without specifying column dimensions.
← Didn't Know|Knew It →