I have a basic question on Java ArrayList.
When ArrayList is declared and initialized using the default constructor, memory space for 10 elements is created. Now, when I add an 11th element, what happens? Will new memory space be created with 20 (or more) element capacity (this requires copying elements from 1st memory location to new location) OR some thing else?
I checked the ArrayList API documentation for Java 1.4.2. But I didn’t find an answer.
Please share the knowledge.
Thanks.
Edit: New links:
A new array is created and the contents of the old one are copied over. That’s all you know at the API level. Quoting from the docs (my emphasis):
In terms of how it actually happens with a specific implementation of
ArrayList(such as Sun’s), in their case you can see the gory details in the source. But of course, relying on the details of a specific implementation isn’t usually a good idea…