Aarrlist , List and array basic details.
- The capacity of an Array is fixed, whereas the capacity of an ArrayList or a List is automatically expanded as required. If the value of the ArrayListCapacity property is changed, the memory reallocation and copying of elements are automatically done.
- ArrayList and List provide methods that add, insert, or remove a range of elements. In Array, you can get or set the value of only one element at a time.
- A synchronized version of ArrayList is easy to create by using the Synchronized method; however, this type of synchronization is relatively inefficient. The Array and List classes leaves it up to the user to implement synchronization. The System.Collections.Concurrent namespace does not provide a concurrent list type, but it does provide a ConcurrentQueue and ConcurrentStack type.
- ArrayList and List provide methods that return read-only and fixed-size wrappers to the collection. Array does not.
- You can set the lower bound of an Array, but the lower bound of an ArrayList or a List is always zero.
- An Array can have multiple dimensions, but an ArrayList or a List always has exactly one dimension. However, you can easily create a list of arrays or a list of lists.
- An Array of a specific type (other than Object) provides better performance than an ArrayList. This is because the elements of ArrayList are of type Object; therefore, boxing and unboxing typically occur when you store or retrieve a value type. However, a List can provide performance similar to an array of the same type if no reallocations are required; that is, if the initial capacity is a good approximation of the maximum size of the list.
Array is in the System namespace; ArrayList is in the System.Collections namespace; List is in the System.Collections.Generic namespace.
No comments:
Post a Comment