ArrayList

ArrayList


A list that dynamically increases in size to hold a number of items.


Implements:

ICloneable 
ICollection 
IEnumerable 
IList 
IObject 
IVersionable 

Public:

Properties:

NameDescription
 Capacity (get) Gets the number of elements that the ArrayList can contain.  
 Capacity (let) Sets the number of elements that the ArrayList can contain.  
 Count (get) Returns the number of items in the list.  
 IsFixedSize (get) Returns if the list is fixed-size.  
 IsReadOnly (get) Returns if the list is read-only.  
 Item (let) Sets the element at the specified index.  
 Item (set) Sets the element at the specified index.  

Methods:

NameDescription
 Add Adds a new item to the end of the list.  
 AddRange Adds the items from a collection to the list.  
 BinarySearch Searches the entire sorted ArrayList for an element using the specified comparer and returns the zero-based index of the element.  
 BinarySearchEx Searches the entire sorted ArrayList for an element using the specified comparer and returns the zero-based index of the element.  
 Clear Clears the list of all values.  
 Clone Returns an ArrayList object containing a copy of the array in the original ArrayList.  
 Contains Determines if the list contains a specific value.  
 CopyTo Copies all of the items to an array.  
 CopyToEx Copies a range of elements to an Array.  
 Equals Returns a boolean indicating if the value and this object instance are the same instance.  
 GetEnumerator Returns an enumerator for an ArrayList.  
 GetHashCode Returns a pseudo-unique number identifying this instance.  
 GetRange Returns an ArrayList object that is a windowed view into the original ArrayList.  
 IndexOf Returns the index of the first occurrence of the value in the list.  
 Insert Inserts a value into the list at the specified index.  
 InsertRange Inserts a collection of items into the list.  
 LastIndexOf Returns the index of the last occurrence of a value in the list.  
 Remove Removes a value from the list.  
 RemoveAt Removes a value from the list at a specified index.  
 RemoveRange Remove a set of items from the list.  
 Reverse Reverses the list of items in the list.  
 SetRange Sets the items in the list to a collection of items.  
 Sort Sorts the items in the entire ArrayList or range of elements in ArrayList.  
 ToArray Returns an array of the items in the list.  
 ToString Returns a string representation of this object instance.  
 TrimToSize Sets the capacity to the number of items in the list.  

Remarks

This class contains an internal array of Variants. As new items are added to the list, the capacity will increase as necessary.

The capacity of the list is the current number of elements in the internal array.

To lower the capacity to save memory, use the TrimToSize method, or set Capacity directly.

The default capacity is 16.

Elements in this collection can be accessed using an integer index. Indexes in this collection are zero-based.

Examples

Public Sub Main()
    Dim List As New ArrayList
    
    List.Add "Hello"
    List.Add "World"
    List.Add "!"
    
    Debug.Print "List"
    Debug.Print CorString.Format("    Count:    {0}", List.Count)
    Debug.Print CorString.Format("    Capacity: {0}", List.Capacity)
    Debug.Print "      Values:"
    PrintValues List
End Sub

Private Sub PrintValues(ByVal List As IEnumerable)
    Dim Value As Variant
    
    For Each Value In List
        Debug.Print "  " & Value;
    Next
End Sub

' This code produces the following:
'
' List
'     Count:    3
'     Capacity: 16
'     Values:  Hello  World  !

See Also

Project CorLib Overview

Class ArrayList Overview

Constructors

ArrayListStatic