The ArrayList class is a weakly-typed collection class. It is found in the System.Collections namespace.
As it is weakly typed, it can contain a heterogeneous collection of elements, that is, of various types.
As a list, it has both a Count (number of elements present) and a Capacity (number of elements the list can contain without resizing). When Count reaches Capacity, Capacity is automatically enlarged.
Constructors: (some of them)
This creates a new empty ArrayList with the default Capacity.
This creates a new empty ArrayList with initial Capacity = C.
Properties: (some of them)
Get or set the number of elements the ArrayList can contain without resizing.
Get the number of elements actually in the ArrayList at present.
Indexer:
Get or set the element at the specified index. Here 0 <= N < Count.
Methods: (a few of them)
Add the element OBJ at the end of the collection.
Remove all elements from the ArrayList; Capacity is unchanged.
This returns true if Target is in the ArrayList and false otherwise.
This copies the entire ArrayList to the one-dimensional array A, which must be compatible.
This returns the index of the first occurrence of Target in the ArrayList, or -1 if not found.
Remove the element at index N. Count is decremented.
Reverse the order of elements in the ArrayList.
Reduce Capacity to the value of Count.
Notes:
There are also methods to sort the ArrayList or to perform a binary search. Sorting requires that the elements should satisfy the IComparer interface (so we need a comparison method).
An ArrayList can contain null values and can have duplicate elements.
For homogeneous elements (all the same type T), an alternative is the List<T> class.
For heterogeneous elements, an alternative is the List<Object> class.