ArrayList: Add

Add

Adds a new item to the end of the list.



 Public Function Add(
	  ByRef Value As Variant ) As Long

Parameters

Value
[ByRef] Variant. The item to be added to the list.

Return Values

Long -  The index at which the item was added.

Remarks

As items are added, the capacity is increased as necessary. The items are appended to the end of the list and maintain the order they were added, provided no other method is used to change the order, such as Insert or Remove.

Exceptions

ExceptionCondition
NotSupportedException The ArrayList is read-only
-or-
The ArrayList is fixed-size.

Examples

In the following example, several items are added to an ArrayList object and then iterated over, displaying the items in the list.

Private Sub Main()
    Dim List As New ArrayList
    
    ' add several elements to the ArrayList
    List.Add "Humpty"
    List.Add "Dumpty"
    List.Add "sat"
    List.Add "on"
    List.Add "a"
    List.Add "wall."
    
    ' Display the contents of the ArrayList
    PrintValues List
End Sub

Private Sub PrintValues(ByVal Source As IEnumerable)
    Dim Value As Variant
    
    ' Iterate over the list
    For Each Value In Source
        ' Write each value onto the same line
        Debug.Print Value; " ";
    Next
End Sub

' This example produces the following output.
'
'    Humpty Dumpty sat on a wall.

See Also

Project CorLib Overview

Class ArrayList Overview

AddRange

Insert

Count