Generic Instance Method 総称体インスタンスメソッド

append(contentsOf:)

Adds the elements of a sequence or collection to the end of this collection. あるシーケンスまたコレクションに属するいくつかの要素をこのコレクションの終わりに加えます。

Declaration 宣言

mutating func append<S>(contentsOf newElements: S) where S : Sequence, Element == S.Element

Parameters パラメータ

newElements

The elements to append to the collection. これらの要素をコレクションへ追加します。

Discussion 解説

The collection being appended to allocates any additional necessary storage to hold the new elements. コレクションは追加されることによって、新しい要素を保有するために何らかの追加的に必要なストレージを割り当てます。

The following example appends the elements of a Range<Int> instance to an array of integers: 次の例は、Range<Int>インスタンスからなるいくらかの要素を整数からなる配列に追加します:


var numbers = [1, 2, 3, 4, 5]
numbers.append(contentsOf: 10...15)
print(numbers)
// Prints "[1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15]"

Complexity: O(m), where m is the length of newElements. 計算量:O(m)、ここでmnewElementsの長さです。

See Also 参照

Combining Arrays 配列を結合する