Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does an ArrayList store?

Tags:

c#

collections

I know I can add object of any type to an ArrayList instance. If I get it right, then reference types are casted to objects (value types are boxed). Also, does an ArrayList actually store lists of objects of reference type object?

like image 889
Mirial Avatar asked Jul 29 '26 22:07

Mirial


1 Answers

Internally the ArrayList class uses a fixed size array object[] (object array) for storage. When you add elements those elements are automatically copied to their respective indexes in the array. When the max size is reached a new array is created with a larger size and the elements are recopied. So it's just a convenience wrapper around a static object array.

like image 172
Darin Dimitrov Avatar answered Aug 01 '26 11:08

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!