Is an ArrayList
is just the interface for a dynamic array? Or are they the same thing?
like: ArrayList
corresponds to dynamic array, HashMap
corresponds to Map
?
except I don't see any Java API for something like a dynamic array, unless it is ArrayList
?
Yes. In short.
A longer explanation is that an ArrayList
is a collection that uses arrays for storage, rather than a linked list, doubly linked list or similar. This means that it gives all the benefits of using an Array, whilst Java looks after the mechanics of sizing the Array for you (dynamically).
I seem to remember that the initial array is created with a default maximum size (which can be specified by the user). Should the collection run out of space, then a larger array is created and the contents of the original array copied into the new one. The increment in size is set to prevent this happening too often, as the operation is fairly costly.
Java also offers the Vector
collection which is similar, but is also thread safe, see: What are the differences between ArrayList and Vector?.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With