Transpose, shared rows and deep copies
Java has no true grid type: a two-dimensional array is an array whose elements are references to other arrays (the rows). That means rows can have different lengths (jagged arrays), and you index with grid[row][col].
Change the code and press Run (Ctrl+Enter). Try to predict the output first, then break it on purpose and read the error. Your edits are saved and match the lesson page.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write a program that builds a 4 x 4 multiplication table in an int[][] (cell = (r + 1) * (c + 1)) and prints it row by row, values separated by spaces.
Write static int[] rowSums(int[][] m) that returns the sum of each row. Test it on the jagged array {{1, 2}, {3, 4, 5}, {6}}.
Write a program that finds the largest value and its position in {{3, 8, 1}, {9, 2, 7}, {4, 6, 5}} and prints max 9 at row 1, col 0.
Explain it without notes
How is int[][] grid = new int[3][4]; laid out in memory?
What is a jagged array, and why can Java have one?
What's the difference between Arrays.toString and Arrays.deepToString on a 2D array, and between equals and deepEquals?
Why does grid.clone() not fully copy a 2D array, and how do you copy it fully?
Expected output
transpose: [[1, 4], [2, 5], [3, 6]]
m = [[99, 2, 3], [4, 5, 6]]
shallow = [[99, 2, 3], [4, 5, 6]]
deep = [[99, 2, 3], [-1, 5, 6]]
equals: false, deepEquals: true