ArrayList 构造函数

定义

初始化 ArrayList 类的新实例。Initializes a new instance of the ArrayList class.

重载

ArrayList()

初始化 ArrayList 类的新实例,该实例为空并且具有默认初始容量。Initializes a new instance of the ArrayList class that is empty and has the default initial capacity.

ArrayList(ICollection)

初始化 ArrayList 类的新实例,该类包含从指定集合复制的元素,并具有与复制的元素数相同的初始容量。Initializes a new instance of the ArrayList class that contains elements copied from the specified collection and that has the same initial capacity as the number of elements copied.

ArrayList(Int32)

初始化 ArrayList 类的新实例,该实例为空并且具有指定的初始容量。Initializes a new instance of the ArrayList class that is empty and has the specified initial capacity.

ArrayList()

初始化 ArrayList 类的新实例,该实例为空并且具有默认初始容量。Initializes a new instance of the ArrayList class that is empty and has the default initial capacity.

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

注解

的容量 ArrayList 是可容纳的元素数 ArrayListThe capacity of an ArrayList is the number of elements that the ArrayList can hold. 当向添加元素时 ArrayList ,将根据需要通过重新分配内部数组来自动增加容量。As elements are added to an ArrayList, the capacity is automatically increased as required by reallocating the internal array.

如果集合的大小可为估算值,则指定初始容量后,无需在将元素添加到时执行多个大小调整操作 ArrayListIf the size of the collection can be estimated, specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the ArrayList.

此构造函数是一种 O(1) 操作。This constructor is an O(1) operation.

另请参阅

适用于

ArrayList(ICollection)

初始化 ArrayList 类的新实例,该类包含从指定集合复制的元素,并具有与复制的元素数相同的初始容量。Initializes a new instance of the ArrayList class that contains elements copied from the specified collection and that has the same initial capacity as the number of elements copied.

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

其元素已复制到新列表的 ICollectionThe ICollection whose elements are copied to the new list.

例外

cnullc is null.

注解

的容量 ArrayList 是可容纳的元素数 ArrayListThe capacity of an ArrayList is the number of elements that the ArrayList can hold. 当向添加元素时 ArrayList ,将根据需要通过重新分配内部数组来自动增加容量。As elements are added to an ArrayList, the capacity is automatically increased as required by reallocating the internal array.

如果集合的大小可为估算值,则指定初始容量后,无需在将元素添加到时执行多个大小调整操作 ArrayListIf the size of the collection can be estimated, specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the ArrayList.

将元素复制到,其 ArrayList 顺序与的读取顺序相同 IEnumerator ICollectionThe elements are copied onto the ArrayList in the same order they are read by the IEnumerator of the ICollection.

此构造函数是一个 O(n) 操作,其中 n 是中的元素数 cThis constructor is an O(n) operation, where n is the number of elements in c.

另请参阅

适用于

ArrayList(Int32)

初始化 ArrayList 类的新实例,该实例为空并且具有指定的初始容量。Initializes a new instance of the ArrayList class that is empty and has the specified initial capacity.

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

参数

capacity
Int32

新列表最初可以存储的元素数。The number of elements that the new list can initially store.

例外

capacity 小于零。capacity is less than zero.

注解

的容量 ArrayList 是可容纳的元素数 ArrayListThe capacity of an ArrayList is the number of elements that the ArrayList can hold. 当向添加元素时 ArrayList ,将根据需要通过重新分配内部数组来自动增加容量。As elements are added to an ArrayList, the capacity is automatically increased as required by reallocating the internal array.

如果集合的大小可为估算值,则指定初始容量后,无需在将元素添加到时执行多个大小调整操作 ArrayListIf the size of the collection can be estimated, specifying the initial capacity eliminates the need to perform a number of resizing operations while adding elements to the ArrayList.

此构造函数是一个 O(n) 操作,其中 ncapacityThis constructor is an O(n) operation, where n is capacity.

另请参阅

适用于