Simple old school C# question: Is an ArrayList
an Array
or a List
? The differences between the two are enormous, so I'm curious if anyone knows the way that ArrayList
s store data?
The List is an interface, and the ArrayList is a class of Java Collection framework. The List creates a static array, and the ArrayList creates a dynamic array for storing the objects. So the List can not be expanded once it is created but using the ArrayList, we can expand the array when needed.
In Java, all collections store only references to objects, not the objects themselves. Both arrays and ArrayList will store a few thousand references in a contiguous array, so they are essentially identical.
ArrayList
behaves like a list (in particular, its count of elements can grow, unlike an array), but it's backed by an array, which will be dynamically resized as needed. Hence the name ArrayList
.
Things that behave like lists don't have to be backed by arrays (they could be linked lists, for example), but ArrayList
is.
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