Possible Duplicate:
When to use ArrayList over array[] in c#?
From the perspective of memory or processor costs, does there appear to be a significant difference between an array and an arrayList object?
1) First and Major difference between Array and ArrayList in Java is that Array is a fixed-length data structure while ArrayList is a variable-length Collection class. You can not change the length of Array once created in Java but ArrayList re-size itself when gets full depending upon the capacity and load factor.
As we all are aware of that arrays are linear data structures providing functionality to add elements in a continuous manner in memory address space whereas ArrayList is a class belonging to the Collection framework.
Data Types Storage: Array can store elements of only one data type but List can store the elements of different data types too. Hence, Array stores homogeneous data values, and the list can store heterogeneous data values.
An array is faster and that is because ArrayList uses a fixed amount of array. However when you add an element to the ArrayList and it overflows. It creates a new Array and copies every element from the old one to the new one.
An array is a low-level data structure that essentially maps to a region in memory. An ArrayList
is a variable length list implemented as an array of object
that is re-allocated as the list grows.
ArrayList
therefore has some overhead related to managing the size of the internal array, and more overhead related to casting objects to the correct type when you access the list.
Also, storing everything as object
means that value types get boxed on write and unboxed on read, which is extremely detrimental to performance. Using List<T>
, a similar but strongly-typed variable size list avoids this issue.
In fact, ArrayList
is practically deprecated in favor of List<T>
since .NET 2.0.
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