«^»
5.3. Creating objects

Suppose you want to store a collection of strings. One way of doing this is to use a class of the FCL called ArrayList. This class allows you to create a flexible array of objects, an array which increases in size whenever necessary.

The ArrayList class provides several constructors. One of these allows you to specify the initial capacity of the ArrayList. Using this constructor, we can create an object using New:

0016:         Dim tLanguages As ArrayList = New ArrayList(2)

This makes the variable tLanguages point to an ArrayList object. It is a bit silly to give the ArrayList a capacity of 2, but this silliness will demonstrate that the ArrayList automatically increases in size when necessary.

The main purpose of a constructor is to give some initial values for aspects of the object being created.