Value Type 🍨🐚Element⚪️🍆
List, an ordered mutable collection.
🍨 provides random access, appending and removing from the last element in
🍨 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 list literals see the Language Reference.
🖍 🆕 🐸
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.
🖍 ❗️ 🐻 🎍🥡 item Element
item to the end of the list in
❗️ 🐽 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.
Removes the item at
index and shifts all following items to the left in
Returns 👍 unless the index is out of range.
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
❗️ 🐔 ➡️ 🔢
Returns the number of items in the list.
🖍 ❗️ 🐥 list 🍨🐚Element🍆
Appends the content of
list to this list. Complexity:
🖍 ❗️ 🐼 ➡️ 🍬Element
Removes the last item from the list and returns it in
O(1). If the list is empty ✨ 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:
🖍 ❗️ 🐴 🎍🥡 capacity 🔢
Ensures that the list is large enough to store at least
You should use this method if you plan to heavily use 🐷 with large indices in order to avoid automatic, useless allocations.
❓ 🐴 ➡️ 🔢
Returns the lists current capacity.
🖍 ❗️ 🦁 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.
Returns a new array with all elements that pass the test implemented by
Tests whether all elements in the array pass the test implemented by
The method immdiately returns 👎 if
callback returned 👎 for one element.
❗️ 🍡 ➡️ 🌳🐚Element🍆
Returns an iterator to iterate over the elements of this list.