ArrayList 建構函式

定義

初始化 ArrayList 類別的新執行個體。

多載

ArrayList()

初始化 ArrayList 類別的新執行個體,這個執行個體為空白且具有預設的初始容量。

ArrayList(ICollection)

初始化 ArrayList 類別的新執行個體,其含有從指定的集合複製過來的項目且具有與複製項目數一樣的初始容量。

ArrayList(Int32)

為具有指定初始容量且為空的 ArrayList 類別,初始化新的執行個體。

ArrayList()

初始化 ArrayList 類別的新執行個體,這個執行個體為空白且具有預設的初始容量。

public:
 ArrayList();
public ArrayList ();
Public Sub New ()

備註

ArrayList 容量是 可以保存的專案 ArrayList 數目。 當元素新增至 ArrayList 時,重新配置內部陣列會自動增加容量。

如果可以估計集合的大小,指定初始容量就不需要在將元素新增至 ArrayList 時執行一些調整大小作業。

此建構函式是 O(1) 作業。

另請參閱

適用於

ArrayList(ICollection)

初始化 ArrayList 類別的新執行個體,其含有從指定的集合複製過來的項目且具有與複製項目數一樣的初始容量。

public:
 ArrayList(System::Collections::ICollection ^ c);
public ArrayList (System.Collections.ICollection c);
new System.Collections.ArrayList : System.Collections.ICollection -> System.Collections.ArrayList
Public Sub New (c As ICollection)

參數

c
ICollection

ICollection,要將其項目複製至新的清單。

例外狀況

cnull

備註

ArrayList 容量是 可以保存的專案 ArrayList 數目。 當元素新增至 ArrayList 時,重新配置內部陣列會自動增加容量。

如果可以估計集合的大小,指定初始容量就不需要在將元素新增至 ArrayList 時執行一些調整大小作業。

專案會依 所 IEnumeratorICollection 讀取的順序複製到 ArrayList 上。

這個建構函式是 O(n) 作業,其中 n 是 中的 c 專案數目。

另請參閱

適用於

ArrayList(Int32)

為具有指定初始容量且為空的 ArrayList 類別,初始化新的執行個體。

public:
 ArrayList(int capacity);
public ArrayList (int capacity);
new System.Collections.ArrayList : int -> System.Collections.ArrayList
Public Sub New (capacity As Integer)

參數

capacity
Int32

新清單一開始能夠儲存的項目數目。

例外狀況

capacity 小於零。

備註

ArrayList 容量是 可以保存的專案 ArrayList 數目。 當元素新增至 ArrayList 時,重新配置內部陣列會自動增加容量。

如果可以估計集合的大小,指定初始容量就不需要在將元素新增至 ArrayList 時執行一些調整大小作業。

這個建構函式是作業 O(n) ,其中 ncapacity

另請參閱

適用於