List
[Common source] [Native source]
A generic ordered collection of elements. Methods in this interface support only read-only access to the list; read/write access is supported through the MutableList interface.
Parameters
E - the type of elements contained in the list. The list is covariant in its element type.
Properties
size
Returns the size of the collection.
Functions
contains
Checks if the specified element is contained in this collection.
containsAll
Checks if all elements in the specified collection are contained in this collection.
get
Returns the element at the specified index in the list.
indexOf
Returns the index of the first occurrence of the specified element in the list, or -1 if the specified element is not contained in the list.
isEmpty
Returns true if the collection is empty [contains no elements], false otherwise.
iterator
Returns an iterator over the elements of this object.
lastIndexOf
Returns the index of the last occurrence of the specified element in the list, or -1 if the specified element is not contained in the list.
listIterator
Returns a list iterator over the elements in this list [in proper sequence].
Returns a list iterator over the elements in this list [in proper sequence], starting at the specified index.
subList
Returns a view of the portion of this list between the specified fromIndex [inclusive] and toIndex [exclusive]. The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa.
Extension Properties
indices
Returns an IntRange of the valid indices for this collection.
lastIndex
Returns the index of the last item in the list or -1 if the list is empty.
Extension Functions
all
Returns true if all elements match the given predicate.
any
Returns true if collection has at least one element.
Returns true if at least one element matches the given predicate.
asIterable
Returns this collection as an Iterable.
asReversed
Returns a reversed read-only view of the original List. All changes made in the original list will be reflected in the reversed one.
asSequence
Creates a Sequence instance that wraps the original collection returning its elements when being iterated.
associate
Returns a Map containing key-value pairs provided by transform function applied to elements of the given collection.
transform:[T]->Pair
]: Map
associateBy
Returns a Map containing the elements from the given collection indexed by the key returned from keySelector function applied to each element.
keySelector:[T]->K
]: Map
Returns a Map containing the values provided by valueTransform and indexed by keySelector functions applied to elements of the given collection.
keySelector:[T]->K,
valueTransform:[T]->V
]: Map
associateByTo
Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function applied to each element of the given collection and value is the element itself.
destination:M,
keySelector:[T]->K
]: M
Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function and and value is provided by the valueTransform function applied to elements of the given collection.
destination:M,
keySelector:[T]->K,
valueTransform:[T]->V
]: M
associateTo
Populates and returns the destination mutable map with key-value pairs provided by transform function applied to each element of the given collection.
destination:M,
transform:[T]->Pair
]: M
associateWith
Returns a Map where keys are elements from the given collection and values are produced by the valueSelector function applied to each element.
valueSelector:[K]->V
]: Map
associateWithTo
Populates and returns the destination mutable map with key-value pairs for each element of the given collection, where key is the element itself and value is provided by the valueSelector function applied to that key.
destination:M,
valueSelector:[K]->V
]: M
binarySearch
Searches this list or its range for the provided element using the binary search algorithm. The list is expected to be sorted into ascending order according to the Comparable natural ordering of its elements, otherwise the result is undefined.
element:T?,
fromIndex:Int=0,
toIndex:Int=size
]: Int
Searches this list or its range for the provided element using the binary search algorithm. The list is expected to be sorted into ascending order according to the specified comparator, otherwise the result is undefined.
element:T,
comparator:Comparator,
fromIndex:Int=0,
toIndex:Int=size
]: Int
Searches this list or its range for an element for which the given comparison function returns zero using the binary search algorithm.
fromIndex:Int=0,
toIndex:Int=size,
comparison:[T]->Int
]: Int
binarySearchBy
Searches this list or its range for an element having the key returned by the specified selector function equal to the provided key value using the binary search algorithm. The list is expected to be sorted into ascending order according to the Comparable natural ordering of keys of its elements. otherwise the result is undefined.
key:K?,
fromIndex:Int=0,
toIndex:Int=size,
selector:[T]->K?
]: Int
chunked
Splits this collection into a list of lists each not exceeding the given size.
Splits this collection into several lists each not exceeding the given size and applies the given transform function to an each.
size:Int,
transform:[List]->R
]: List
component1
Returns 1st element from the list.
component2
Returns 2nd element from the list.
component3
Returns 3rd element from the list.
component4
Returns 4th element from the list.
component5
Returns 5th element from the list.
contains
Returns true if element is found in the collection.
containsAll
Checks if all elements in the specified collection are contained in this collection.
elements:Collection
]: Boolean
count
Returns the number of elements matching the given predicate.
distinct
Returns a list containing only distinct elements from the given collection.
distinctBy
Returns a list containing only elements from the given collection having distinct keys returned by the given selector function.
selector:[T]->K
]: List
drop
Returns a list containing all elements except first n elements.
dropLast
Returns a list containing all elements except last n elements.
dropLastWhile
Returns a list containing all elements except last elements that satisfy the given predicate.
predicate:[T]->Boolean
]: List
dropWhile
Returns a list containing all elements except first elements that satisfy the given predicate.
predicate:[T]->Boolean
]: List
elementAt
Returns an element at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this list.
elementAtOrElse
Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this list.
index:Int,
defaultValue:[Int]->T
]: T
Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this collection.
index:Int,
defaultValue:[Int]->T
]: T
elementAtOrNull
Returns an element at the given index or null if the index is out of bounds of this list.
filter
Returns a list containing only elements matching the given predicate.
predicate:[T]->Boolean
]: List
filterIndexed
Returns a list containing only elements matching the given predicate.
predicate:[index:Int,T]->Boolean
]: List
filterIndexedTo
Appends all elements matching the given predicate to the given destination.
destination:C,
predicate:[index:Int,T]->Boolean
]: C
filterIsInstance
Returns a list containing all elements that are instances of specified type parameter R.
Returns a list containing all elements that are instances of specified class.
klass:Class
]: List
filterIsInstanceTo
Appends all elements that are instances of specified type parameter R to the given destination.
destination:C
]: C
Appends all elements that are instances of specified class to the given destination.
destination:C,
klass:Class
]: C
filterNot
Returns a list containing all elements not matching the given predicate.
predicate:[T]->Boolean
]: List
filterNotNull
Returns a list containing all elements that are not null.
filterNotNullTo
Appends all elements that are not null to the given destination.
destination:C
]: C
filterNotTo
Appends all elements not matching the given predicate to the given destination.
destination:C,
predicate:[T]->Boolean
]: C
filterTo
Appends all elements matching the given predicate to the given destination.
destination:C,
predicate:[T]->Boolean
]: C
find
Returns the first element matching the given predicate, or null if no such element was found.
findLast
Returns the last element matching the given predicate, or null if no such element was found.
first
Returns first element.
Returns the first element matching the given predicate.
firstNotNullOf
Returns the first non-null value produced by transform function being applied to elements of this collection in iteration order, or throws NoSuchElementException if no non-null value was produced.
transform:[T]->R?
]: R
firstNotNullOfOrNull
Returns the first non-null value produced by transform function being applied to elements of this collection in iteration order, or null if no non-null value was produced.
transform:[T]->R?
]: R?
firstOrNull
Returns the first element, or null if the list is empty.
Returns the first element matching the given predicate, or null if element was not found.
predicate:[T]->Boolean
]: T?
flatMap
Returns a single list of all elements yielded from results of transform function being invoked on each element of original collection.
transform:[T]->Iterable
]: List
transform:[T]->Sequence
]: List
flatMapIndexed
Returns a single list of all elements yielded from results of transform function being invoked on each element and its index in the original collection.
transform:[index:Int,T]->Iterable
]: List
transform:[index:Int,T]->Sequence
]: List
flatMapIndexedTo
Appends all elements yielded from results of transform function being invoked on each element and its index in the original collection, to the given destination.
destination:C,
transform:[index:Int,T]->Iterable
]: C
destination:C,
transform:[index:Int,T]->Sequence
]: C
flatMapTo
Appends all elements yielded from results of transform function being invoked on each element of original collection, to the given destination.
destination:C,
transform:[T]->Iterable
]: C
destination:C,
transform:[T]->Sequence
]: C
flatten
Returns a single list of all elements from all collections in the given collection.
fold
Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element.
initial:R,
operation:[acc:R,T]->R
]: R
foldIndexed
Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element with its index in the original collection.
initial:R,
operation:[index:Int,acc:R,T]->R
]: R
foldRight
Accumulates value starting with initial value and applying operation from right to left to each element and current accumulator value.
initial:R,
operation:[T,acc:R]->R
]: R
foldRightIndexed
Accumulates value starting with initial value and applying operation from right to left to each element with its index in the original list and current accumulator value.
initial:R,
operation:[index:Int,T,acc:R]->R
]: R
forEach
Performs the given action on each element.
forEachIndexed
Performs the given action on each element, providing sequential index with the element.
action:[index:Int,T]->Unit]
getOrElse
Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this list.
index:Int,
defaultValue:[Int]->T
]: T
getOrNull
Returns an element at the given index or null if the index is out of bounds of this list.
groupBy
Groups elements of the original collection by the key returned by the given keySelector function applied to each element and returns a map where each group key is associated with a list of corresponding elements.
keySelector:[T]->K
]: Map
Groups values returned by the valueTransform function applied to each element of the original collection by the key returned by the given keySelector function applied to the element and returns a map where each group key is associated with a list of corresponding values.
keySelector:[T]->K,
valueTransform:[T]->V
]: Map
groupByTo
Groups elements of the original collection by the key returned by the given keySelector function applied to each element and puts to the destination map each group key associated with a list of corresponding elements.
destination:M,
keySelector:[T]->K
]: M
Groups values returned by the valueTransform function applied to each element of the original collection by the key returned by the given keySelector function applied to the element and puts to the destination map each group key associated with a list of corresponding values.
destination:M,
keySelector:[T]->K,
valueTransform:[T]->V
]: M
groupingBy
Creates a Grouping source from a collection to be used later with one of group-and-fold operations using the specified keySelector function to extract a key from each element.
keySelector:[T]->K
]: Grouping
ifEmpty
Returns this array if it's not empty or the result of calling defaultValue function if the array is empty.
defaultValue:[]->R
]: R where C:Array, C:R
indexOf
Returns first index of element, or -1 if the list does not contain element.
Returns first index of element, or -1 if the collection does not contain element.
indexOfFirst
Returns index of the first element matching the given predicate, or -1 if the list does not contain such element.
Returns index of the first element matching the given predicate, or -1 if the collection does not contain such element.
predicate:[T]->Boolean
]: Int
indexOfLast
Returns index of the last element matching the given predicate, or -1 if the list does not contain such element.
Returns index of the last element matching the given predicate, or -1 if the collection does not contain such element.
predicate:[T]->Boolean
]: Int
intersect
Returns a set containing all elements that are contained by both this collection and the specified collection.
other:Iterable
]: Set
isNotEmpty
Returns true if the collection is not empty.
isNullOrEmpty
Returns true if this nullable collection is either null or empty.
joinTo
Appends the string from all the elements separated using separator and using the given prefix and postfix if supplied.
buffer:A,
separator:CharSequence=", ",
prefix:CharSequence="",
postfix:CharSequence="",
limit:Int=-1,
truncated:CharSequence="...",
transform:[[T]->CharSequence]?=null
]: A
joinToString
Creates a string from all the elements separated using separator and using the given prefix and postfix if supplied.
separator:CharSequence=", ",
prefix:CharSequence="",
postfix:CharSequence="",
limit:Int=-1,
truncated:CharSequence="...",
transform:[[T]->CharSequence]?=null
]: String
last
Returns the last element.
Returns the last element matching the given predicate.
lastIndexOf
Returns last index of element, or -1 if the list does not contain element.
Returns last index of element, or -1 if the collection does not contain element.
lastOrNull
Returns the last element, or null if the list is empty.
Returns the last element matching the given predicate, or null if no such element was found.
map
Returns a list containing the results of applying the given transform function to each element in the original collection.
mapIndexed
Returns a list containing the results of applying the given transform function to each element and its index in the original collection.
transform:[index:Int,T]->R
]: List
mapIndexedNotNull
Returns a list containing only the non-null results of applying the given transform function to each element and its index in the original collection.
transform:[index:Int,T]->R?
]: List
mapIndexedNotNullTo
Applies the given transform function to each element and its index in the original collection and appends only the non-null results to the given destination.
destination:C,
transform:[index:Int,T]->R?
]: C
mapIndexedTo
Applies the given transform function to each element and its index in the original collection and appends the results to the given destination.
destination:C,
transform:[index:Int,T]->R
]: C
mapNotNull
Returns a list containing only the non-null results of applying the given transform function to each element in the original collection.
transform:[T]->R?
]: List
mapNotNullTo
Applies the given transform function to each element in the original collection and appends only the non-null results to the given destination.
destination:C,
transform:[T]->R?
]: C
mapTo
Applies the given transform function to each element of the original collection and appends the results to the given destination.
destination:C,
transform:[T]->R
]: C
maxBy
selector:[T]->R
]: T?
maxByOrNull
Returns the first element yielding the largest value of the given function or null if there are no elements.
selector:[T]->R
]: T?
maxOf
Returns the largest value among all values produced by selector function applied to each element in the collection.
selector:[T]->R
]: R
maxOfOrNull
Returns the largest value among all values produced by selector function applied to each element in the collection or null if there are no elements.
selector:[T]->Double
]: Double?
selector:[T]->Float
]: Float?
selector:[T]->R
]: R?
maxOfWith
Returns the largest value according to the provided comparator among all values produced by selector function applied to each element in the collection.
comparator:Comparator,
selector:[T]->R
]: R
maxOfWithOrNull
Returns the largest value according to the provided comparator among all values produced by selector function applied to each element in the collection or null if there are no elements.
comparator:Comparator,
selector:[T]->R
]: R?
maxWith
maxWithOrNull
Returns the first element having the largest value according to the provided comparator or null if there are no elements.
comparator:Comparator
]: T?
minBy
selector:[T]->R
]: T?
minByOrNull
Returns the first element yielding the smallest value of the given function or null if there are no elements.
selector:[T]->R
]: T?
minOf
Returns the smallest value among all values produced by selector function applied to each element in the collection.
selector:[T]->R
]: R
minOfOrNull
Returns the smallest value among all values produced by selector function applied to each element in the collection or null if there are no elements.
selector:[T]->Double
]: Double?
selector:[T]->Float
]: Float?
selector:[T]->R
]: R?
minOfWith
Returns the smallest value according to the provided comparator among all values produced by selector function applied to each element in the collection.
comparator:Comparator,
selector:[T]->R
]: R
minOfWithOrNull
Returns the smallest value according to the provided comparator among all values produced by selector function applied to each element in the collection or null if there are no elements.
comparator:Comparator,
selector:[T]->R
]: R?
minus
Returns a list containing all elements of the original collection without the first occurrence of the given element.
Returns a list containing all elements of the original collection except the elements contained in the given elements array.
elements:Array
]: List
Returns a list containing all elements of the original collection except the elements contained in the given elements collection.
elements:Iterable
]: List
Returns a list containing all elements of the original collection except the elements contained in the given elements sequence.
elements:Sequence
]: List
minusElement
Returns a list containing all elements of the original collection without the first occurrence of the given element.
minWith
minWithOrNull
Returns the first element having the smallest value according to the provided comparator or null if there are no elements.
comparator:Comparator
]: T?
none
Returns true if the collection has no elements.
Returns true if no elements match the given predicate.
onEach
Performs the given action on each element and returns the collection itself afterwards.
onEachIndexed
Performs the given action on each element, providing sequential index with the element, and returns the collection itself afterwards.
action:[index:Int,T]->Unit
]: C
orEmpty
Returns this List if it's not null and the empty list otherwise.
partition
Splits the original collection into pair of lists, where first list contains elements for which predicate yielded true, while second list contains elements for which predicate yielded false.
predicate:[T]->Boolean
]: Pair
plus
Returns a list containing all elements of the original collection and then the given element.
Returns a list containing all elements of the original collection and then all elements of the given elements array.
elements:Array
]: List
elements:Array
]: List
Returns a list containing all elements of the original collection and then all elements of the given elements collection.
elements:Iterable
]: List
elements:Iterable
]: List
Returns a list containing all elements of the original collection and then all elements of the given elements sequence.
elements:Sequence
]: List
elements:Sequence
]: List
plusElement
Returns a list containing all elements of the original collection and then the given element.
random
Returns a random element from this collection.
Returns a random element from this collection using the specified source of randomness.
randomOrNull
Returns a random element from this collection, or null if this collection is empty.
Returns a random element from this collection using the specified source of randomness, or null if this collection is empty.
reduce
Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element.
operation:[acc:S,T]->S
]: S
reduceIndexed
Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element with its index in the original collection.
operation:[index:Int,acc:S,T]->S
]: S
reduceIndexedOrNull
Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element with its index in the original collection.
operation:[index:Int,acc:S,T]->S
]: S?
reduceOrNull
Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element.
operation:[acc:S,T]->S
]: S?
reduceRight
Accumulates value starting with the last element and applying operation from right to left to each element and current accumulator value.
operation:[T,acc:S]->S
]: S
reduceRightIndexed
Accumulates value starting with the last element and applying operation from right to left to each element with its index in the original list and current accumulator value.
operation:[index:Int,T,acc:S]->S
]: S
reduceRightIndexedOrNull
Accumulates value starting with the last element and applying operation from right to left to each element with its index in the original list and current accumulator value.
operation:[index:Int,T,acc:S]->S
]: S?
reduceRightOrNull
Accumulates value starting with the last element and applying operation from right to left to each element and current accumulator value.
operation:[T,acc:S]->S
]: S?
requireNoNulls
Returns an original collection containing all the non-null elements, throwing an IllegalArgumentException if there are any null elements.
reversed
Returns a list with elements in reversed order.
runningFold
Returns a list containing successive accumulation values generated by applying operation from left to right to each element and current accumulator value that starts with initial value.
initial:R,
operation:[acc:R,T]->R
]: List
runningFoldIndexed
Returns a list containing successive accumulation values generated by applying operation from left to right to each element, its index in the original collection and current accumulator value that starts with initial value.
initial:R,
operation:[index:Int,acc:R,T]->R
]: List
runningReduce
Returns a list containing successive accumulation values generated by applying operation from left to right to each element and current accumulator value that starts with the first element of this collection.
operation:[acc:S,T]->S
]: List
runningReduceIndexed
Returns a list containing successive accumulation values generated by applying operation from left to right to each element, its index in the original collection and current accumulator value that starts with the first element of this collection.
operation:[index:Int,acc:S,T]->S
]: List
scan
Returns a list containing successive accumulation values generated by applying operation from left to right to each element and current accumulator value that starts with initial value.
initial:R,
operation:[acc:R,T]->R
]: List
scanIndexed
Returns a list containing successive accumulation values generated by applying operation from left to right to each element, its index in the original collection and current accumulator value that starts with initial value.
initial:R,
operation:[index:Int,acc:R,T]->R
]: List
shuffled
Returns a new list with the elements of this list randomly shuffled using the specified random instance as the source of randomness.
single
Returns the single element, or throws an exception if the list is empty or has more than one element.
Returns the single element matching the given predicate, or throws exception if there is no or more than one matching element.
singleOrNull
Returns single element, or null if the list is empty or has more than one element.
Returns the single element matching the given predicate, or null if element was not found or more than one element was found.
predicate:[T]->Boolean
]: T?
slice
Returns a list containing elements at indices in the specified indices range.
Returns a list containing elements at specified indices.
sortedBy
Returns a list of all elements sorted according to natural sort order of the value returned by specified selector function.
selector:[T]->R?
]: List
sortedByDescending
Returns a list of all elements sorted descending according to natural sort order of the value returned by specified selector function.
selector:[T]->R?
]: List
sortedWith
Returns a list of all elements sorted according to the specified comparator.
comparator:Comparator
]: List
subtract
Returns a set containing all elements that are contained by this collection and not contained by the specified collection.
other:Iterable
]: Set
sumBy
Returns the sum of all values produced by selector function applied to each element in the collection.
sumByDouble
Returns the sum of all values produced by selector function applied to each element in the collection.
selector:[T]->Double
]: Double
sumOf
Returns the sum of all values produced by selector function applied to each element in the collection.
selector:[T]->BigDecimal
]: BigDecimal
selector:[T]->BigInteger
]: BigInteger
take
Returns a list containing first n elements.
takeLast
Returns a list containing last n elements.
takeLastWhile
Returns a list containing last elements satisfying the given predicate.
predicate:[T]->Boolean
]: List
takeWhile
Returns a list containing first elements satisfying the given predicate.
predicate:[T]->Boolean
]: List
toBooleanArray
Returns an array of Boolean containing all of the elements of this collection.
toByteArray
Returns an array of Byte containing all of the elements of this collection.
toCharArray
Returns an array of Char containing all of the elements of this collection.
toCollection
Appends all elements to the given destination collection.
destination:C
]: C
toCStringArray
Convert this list of Kotlin strings to C array of C strings, allocating memory for the array and C strings with given AutofreeScope.
autofreeScope:AutofreeScope
]: CPointer
toCValues
toDoubleArray
Returns an array of Double containing all of the elements of this collection.
toFloatArray
Returns an array of Float containing all of the elements of this collection.
toHashSet
Returns a new HashSet of all elements.
toIntArray
Returns an array of Int containing all of the elements of this collection.
toList
Returns a List containing all elements.
toLongArray
Returns an array of Long containing all of the elements of this collection.
toMap
Returns a new map containing all key-value pairs from the given collection of pairs.
Populates and returns the destination mutable map with key-value pairs from the given collection of pairs.
destination:M
]: M
toMutableSet
Returns a new MutableSet containing all distinct elements from the given collection.
toSet
Returns a Set of all elements.
toShortArray
Returns an array of Short containing all of the elements of this collection.
toSortedSet
Returns a new SortedSet of all elements.
comparator:Comparator
]: SortedSet
toUByteArray
Returns an array of UByte containing all of the elements of this collection.
toUIntArray
Returns an array of UInt containing all of the elements of this collection.
toULongArray
Returns an array of ULong containing all of the elements of this collection.
toUShortArray
Returns an array of UShort containing all of the elements of this collection.
union
Returns a set containing all distinct elements from both collections.
unzip
Returns a pair of lists, where first list is built from the first values of each pair from this collection, second list is built from the second values of each pair from this collection.
waitForMultipleFutures
millis:Int
]: Set
windowed
Returns a list of snapshots of the window of the given size sliding along this collection with the given step, where each snapshot is a list.
size:Int,
step:Int=1,
partialWindows:Boolean=false
]: List
Returns a list of results of applying the given transform function to an each list representing a view over the window of the given size sliding along this collection with the given step.
size:Int,
step:Int=1,
partialWindows:Boolean=false,
transform:[List]->R
]: List
withIndex
Returns a lazy Iterable that wraps each element of the original collection into an IndexedValue containing the index of that element and the element itself.
zip
Returns a list of pairs built from the elements of this collection and the other array with the same index. The returned list has length of the shortest collection.
other:Array
]: List
Returns a list of values built from the elements of this collection and the other array with the same index using the provided transform function applied to each pair of elements. The returned list has length of the shortest collection.
other:Array,
transform:[a:T,b:R]->V
]: List
Returns a list of pairs built from the elements of this collection and other collection with the same index. The returned list has length of the shortest collection.
other:Iterable
]: List
Returns a list of values built from the elements of this collection and the other collection with the same index using the provided transform function applied to each pair of elements. The returned list has length of the shortest collection.
other:Iterable,
transform:[a:T,b:R]->V
]: List
zipWithNext
Returns a list of pairs of each two adjacent elements in this collection.
Returns a list containing the results of applying the given transform function to an each pair of two adjacent elements in this collection.
transform:[a:T,b:T]->R
]: List
Inheritors
AbstractList
Provides a skeletal implementation of the read-only List interface.
AbstractCollection,
List
MutableList
A generic ordered collection of elements that supports adding and removing elements.