Package
Conforms to
Initializers
Methods
Value Type π¨πElementβͺοΈπ
List, an ordered mutable collection.
π¨ provides random access, appending and removing from the last element in O(1)
.
π¨ is a value type. This means that copies of π¨ are independent:
πΏ π€redπ€ π€greenπ€ π€blueπ€ π β‘οΈ colors
colors β‘οΈ ππotherColors
π» otherColors π€pinkπ€βοΈ
In the above example the dictionary in colors
will still contain only three strings as only otherColors
was modified.
To learn more about collection literals see the Language Reference.
Initializers
π
π π
Creates an empty list.
πβΆοΈπ΄
π πβΆοΈπ΄ capacity π’
Creates an empty list with the given initial capacity.
Note that this initializer does not place any values in the list. This initializer can be used for better performance if the number of values that will be added is known in advance.
π
π π ππ₯‘ repeatedValue Element count π’
Creates an containing the specified number of a single, repeated value.
Methods
π»βοΈ
π βοΈ π» ππ₯‘ item Element
Appends item
to the end of the list in O(1)
.
π½βοΈ
βοΈ π½ index π’ β‘οΈ β΄οΈElement
Gets the item at index in O(1)
. index must be greater than or equal to 0 and less than πβ or the program will panic.
π½β‘οΈ
π β‘οΈ π½ ππ₯‘ value Element index π’
Sets value at index. index must be greater than or equal to 0 and less than πβ or the program will panic.
π¨βοΈ
π βοΈ π¨ index π’ β‘οΈ π
Removes the item at index
and shifts all following items to the left in O(n)
.
Returns π unless the index is out of range.
π΅βοΈ
π βοΈ π΅ index π’ ππ₯‘ item Element β‘οΈ π
Inserts the given values before the element with the given index.
All items beginning from index
are shifted to the right and item
is then inserted at index
. Complexity: O(n)
.
π₯βοΈ
π βοΈ π₯ list π¨πElementπ
Appends the content of list
to this list. Complexity: O(n)
.
πΌβοΈ
π βοΈ πΌ β‘οΈ π¬Element
Removes the last item from the list and returns it in O(1)
. If the list is empty no value is returned.
πβοΈ
π βοΈ π
Removes all elements from the list but keeps the listβs capacity.
This can be much more efficient than using a new list. Complexity: O(n)
.
π΄βοΈ
π βοΈ π΄ capacity π’
Ensures that the list is large enough to store at least capacity
elements.
You should use this method if you plan to heavily use π· with large indices in order to avoid automatic, useless allocations.
Complexity: O(n)
.
π¦βοΈ
π βοΈ π¦ comparator πElementElementβ‘οΈπ’π
Sorts this array in place using the quick sort algorithm.
comparator
must return an integer less than, equal to, or greater than 0, if the first argument is considered respectively less than, equal to, or greater than the second.
πΉβοΈ
π βοΈ πΉ
Shuffles the list in place using a FisherβYates shuffle.
π°βοΈ
βοΈ π°πAβͺοΈπ callback πElementβ‘οΈAπ β‘οΈ π¨πAπ
Calls callback with each element in the list and appends the returned value to the end of a new list.
πβοΈ
βοΈ π callback πElementβ‘οΈππ β‘οΈ π¨πElementπ
Returns a new array with all elements that pass the test implemented by callback
.
π¦β
β π¦πAππElementππ ππ₯‘ value A β‘οΈ π
Returns π if at least one element in the list is equal to value
.
π―βοΈ
βοΈ π― callback πElementβ‘οΈππ β‘οΈ π
Tests whether all elements in the array pass the test implemented by callback
.
The method immdiately returns π if callback
returned π for one element.
π§βοΈ
βοΈ π§ callable πElementElementβ‘οΈElementπ β‘οΈ π¬Element
Combines all elements in this list by using the binary operation described by callable
. The first argument is the result of the previous call of the callable, while the first value of the list is used as the initial value and never passed as the second argument.
π€βοΈ
βοΈ π€πAβͺοΈπ ππ₯‘ start A callable πAElementβ‘οΈAπ β‘οΈ A
Combines all elements in this list by using the binary operation described by callable
. The first argument is the result of the previous call of the callable, with start
used as the initial value passed along with the first element of the list.
π¦βοΈ
π βοΈ π¦
Reverses the list in place.
π
ππAππElementππ other π¨πAπ β‘οΈ π
Tests whether this array and other
are equal.
π‘βοΈ
βοΈ π‘ β‘οΈ π³πElementπ
Returns an iterator to iterate over the elements of this list.