Java ArrayList visualizer

An ArrayList keeps its items in order and shifts them when you insert or remove. Step through the program and watch the list change after every call.

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

  • add puts each name at the end of the list.
  • add(1, ...) inserts at index 1, so every item after it moves one place to the right.
  • remove takes an item out and the items after it slide left to close the gap.

Try changing it

  • Call remove(0) instead of removing by name and compare the result.
  • Add a loop that removes every name longer than three letters.

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.