ArrayList of Arrays for Interactive Shapes

The key here is “same array”. If you’re adding the same array (polygon.add(pos);), changing its content will reflect everywhere within polygon.

Containers don’t store whole objects, but just their references (memory address).

3 Likes