The ArrayList is a type of collection. These allow dynamic resizing. ArrayLists are actual objects. Therefore, we must define them like this:

Dim listName As New ArrayList()

ArrayLists are not strongly typed. This means (although not recommended) you can put different datatypes into a single ArrayList. For example:

listName.Add("one")
listName.Add(4)
listName.Add(5.04)

NOTE: Again, using ArrayLists in this way is bad programming and is NOT recommended. Only do this if you absolutely have to.

To retrieve a value from an ArrayList, we use another variable. For example:

Dim FirstItem As String = CType(listName(0), String)

In this scenario, we set the value of the string FirstItem as the value of the first value (0) in the ArrayList listName. When using an ArrayList in this way, we must use the CType function to ensure the value of the object is the correct type of object. The CType function takes a value and converts it to the specified variable type (in this case a String).

Previous Next

Startup Discount
Small Business?
Contact us for an Enormous Discount!