Say we have an array
A
of three ArrayLists
X
, Y
, Z
with each having initial capacity of 10. Then A
would be allocated space for capacity of 30, right? So what happens when Y
gets mutated and now has capacity 20? Or if the array accounts for such mutations and gets allocated more space then it initially needs, how much space does it get (e.g. in Java) and what happens when this space is used up?
Asked
Active
Viewed 84 times
0

timtam
- 220
- 2
- 9
1 Answers
3
No. A
has capacity three, and stores pointers to ArrayList
objects that live somewhere else in memory -- somewhere arbitrary.
(Then each ArrayList
object itself has a pointer to an array with size 10, When Y
gets mutated and now has capacity 20, the original size-10 array is discarded and Y
's pointer is changed to point to a new array of size 20.)

Louis Wasserman
- 191,574
- 25
- 345
- 413