TrimToSize Method

Sets the capacity to the actual number of elements in the ArrayList object.

Syntax

Object.TrimToSize()

Arguments - Object: Required. Always the name of ArrayList object.

Remarks

The following example illustrates the use of the TrimToSize method.

Example 1:

'Create ArrayList Object
Dim Obj
Set Obj = CreateObject("System.Collections.ArrayList")

'Add Elements to the end of ArrayList Object
Dim Index
Index = Obj.Add(10)
Index = Obj.Add(40)
Index = Obj.Add(20)

'Sets the capacity to the actual number of elements in the ArrayList object
Obj.TrimToSize ()
'Output: Internally ArrayList Capacity changed to the actual number of elements in the ArrayList object