TrimToSize 方法

將容量設為 ArrayList 物件中的實際元素數。

語法

Object.TrimToSize()

引數 - Object必要。一律是 ArrayList 物件的名稱。

備註

下列範例說明 TrimToSize 方法的用法。

範例 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