String Manipulation and 2D Arrays Flashcards
6 cards from real AP CSA practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 6 String Manipulation and 2D Arrays flashcards as text
What does `str.toUpperCase()` do?
Answer: Returns a new String with all characters converted to uppercase
toUpperCase() returns a new String with all alphabetic characters converted to uppercase; Strings in Java are immutable so the original is unchanged.
How do you access the element in row 2, column 3 of a 2D array called `grid`?
Answer: grid[2][3]
2D array elements are accessed with [row][column] syntax; grid[2][3] accesses row 2 (third row), column 3 (fourth column).
What nested loop structure traverses all elements of a 2D array `int[][] m` with r rows and c columns?
Answer: for(int i=0;i<m.length;i++) for(int j=0;j<m[i].length;j++)
The outer loop uses m.length for rows and the inner loop uses m[i].length for columns, correctly visiting every element.
What does `str.substring(3)` return for `str = "JavaCode"`?
Answer: "aCode"
substring(3) returns all characters from index 3 to the end; J(0),a(1),v(2),a(3)Code → "aCode".
What is the result of `"5" + 3 + 2` in Java?
Answer: "532"
Java evaluates left to right: "5"+3 is String concatenation giving "53", then "53"+2 gives "532" — not arithmetic.
How do you fill an entire 2D array `grid` of size n×m with the value 0?
Answer: Declare it as `int[][] grid = new int[n][m]` (auto-initialized to 0)
Java automatically initializes int array elements to 0, so `new int[n][m]` creates a 2D array already filled with zeros.