Tracing the ArrayMap
Let’s trace a sequence of operations and watch how the backing array and size change. Each slot is drawn as key: value, and only the filled part of the array is shown.
We start with new ArrayMap<>() and put three new keys: put("ann", "x7"), put("bo", "q3"), then put("cal", "m9"). Each call appends a new entry at the next free slot and returns true.
┌─────────┬─────────┬─────────┐
│ ann: x7 │ bo: q3 │ cal: m9 │ size = 3
└─────────┴─────────┴─────────┘
0 1 2
Now put("bo", "z5") finds bo at index 1, replaces its value, and returns false. The size stays 3.
┌─────────┬─────────┬─────────┐
│ ann: x7 │ bo: z5 │ cal: m9 │ size = 3
└─────────┴─────────┴─────────┘
0 1 2
get("cal") returns m9, and get("dan") searches to the end and returns null.
Removals work as in the ArraySet trace: remove moves the last entry into the gap.