Java 2D array visualizer

A 2D array in Java is an array of rows, where each row is its own array. Step through the nested loops and watch every cell fill in, row by row.

Source

line 1
Line that just executed Next line to execute
Sign in to share

Call stack

1
main()
line 1
Step 1/1

What to watch

  • new int[3][4] makes three row arrays, each with four zeros.
  • The outer loop picks a row and the inner loop walks across its columns.
  • grid[row].length is the number of columns in that row.

Try changing it

  • Swap the loops so it fills column by column.
  • Make the rows different lengths and see how the arrays change.

Edit the code above and press Visualize to see your version run.

More Java examples

Or open the Java visualizer and paste your own code.