Array

Common
JVM
JS
Native
1.0
class Array<T>
For Common, JVM, JS

Represents an array (specifically, a Java array when targeting the JVM platform). Array instances can be created using the arrayOf, arrayOfNulls and emptyArray standard library functions. See Kotlin language documentation for more information on arrays.

For Native

Represents an array. Array instances can be created using the constructor, arrayOf, arrayOfNulls and emptyArray standard library functions. See Kotlin language documentation for more information on arrays.

Constructors

Common
JVM
JS
Native
1.0

<init>

Creates a new array with the specified size, where each element is calculated by calling the specified init function. The init function returns an array element given its index.

<init>(size: Int, init: (Int) -> T)

Properties

Common
JVM
JS
Native
1.0

size

Returns the number of elements in the array.

val size: Int

Functions

Common
JVM
JS
Native
1.0

get

Returns the array element at the specified index. This method can be called using the index operator:

operator fun get(index: Int): T
Common
JVM
JS
Native
1.0

iterator

Creates an iterator for iterating over the elements of the array.

operator fun iterator(): Iterator<T>
Common
JVM
JS
Native
1.0

set

Sets the array element at the specified index to the specified value. This method can be called using the index operator:

operator fun set(index: Int, value: T)

Extension Properties

Common
JVM
JS
Native
1.0

indices

Returns the range of valid indices for the array.

val <T> Array<out T>.indices: IntRange
Common
JVM
JS
Native
1.0

lastIndex

Returns the last valid index for the array.

val <T> Array<out T>.lastIndex: Int

Extension Functions

Common
JVM
JS
Native
1.0

all

Returns true if all elements match the given predicate.

fun <T> Array<out T>.all(predicate: (T) -> Boolean): Boolean
Common
JVM
JS
Native
1.0

any

Returns true if array has at least one element.

fun <T> Array<out T>.any(): Boolean

Returns true if at least one element matches the given predicate.

fun <T> Array<out T>.any(predicate: (T) -> Boolean): Boolean
Common
JVM
JS
Native
1.0

asIterable

Creates an Iterable instance that wraps the original array returning its elements when being iterated.

fun <T> Array<out T>.asIterable(): Iterable<T>
Common
JVM
JS
Native
1.0

asSequence

Creates a Sequence instance that wraps the original array returning its elements when being iterated.

fun <T> Array<out T>.asSequence(): Sequence<T>
Common
JVM
JS
Native
1.0

associate

Returns a Map containing key-value pairs provided by transform function applied to elements of the given array.

fun <T, K, V> Array<out T>.associate(
    transform: (T) -> Pair<K, V>
): Map<K, V>
Common
JVM
JS
Native
1.0

associateBy

Returns a Map containing the elements from the given array indexed by the key returned from keySelector function applied to each element.

fun <T, K> Array<out T>.associateBy(
    keySelector: (T) -> K
): Map<K, T>

Returns a Map containing the values provided by valueTransform and indexed by keySelector functions applied to elements of the given array.

fun <T, K, V> Array<out T>.associateBy(
    keySelector: (T) -> K,
    valueTransform: (T) -> V
): Map<K, V>
Common
JVM
JS
Native
1.0

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 array and value is the element itself.

fun <T, K, M : MutableMap<in K, in T>> Array<out T>.associateByTo(
    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 array.

fun <T, K, V, M : MutableMap<in K, in V>> Array<out T>.associateByTo(
    destination: M,
    keySelector: (T) -> K,
    valueTransform: (T) -> V
): M
Common
JVM
JS
Native
1.0

associateTo

Populates and returns the destination mutable map with key-value pairs provided by transform function applied to each element of the given array.

fun <T, K, V, M : MutableMap<in K, in V>> Array<out T>.associateTo(
    destination: M,
    transform: (T) -> Pair<K, V>
): M
Common
JVM
JS
Native
1.0

average

Returns an average value of elements in the array.

fun Array<out Byte>.average(): Double
fun Array<out Short>.average(): Double
fun Array<out Int>.average(): Double
fun Array<out Long>.average(): Double
fun Array<out Float>.average(): Double
fun Array<out Double>.average(): Double
JVM
1.0

binarySearch

Searches the array or the range of the array for the provided element using the binary search algorithm. The array is expected to be sorted according to the specified comparator, otherwise the result is undefined.

fun <T> Array<out T>.binarySearch(
    element: T,
    comparator: Comparator<in T>,
    fromIndex: Int = 0,
    toIndex: Int = size
): Int

Searches the array or the range of the array for the provided element using the binary search algorithm. The array is expected to be sorted, otherwise the result is undefined.

fun <T> Array<out T>.binarySearch(
    element: T,
    fromIndex: Int = 0,
    toIndex: Int = size
): Int
Common
JVM
JS
Native
1.0

component1

Returns 1st element from the collection.

operator fun <T> Array<out T>.component1(): T
Common
JVM
JS
Native
1.0

component2

Returns 2nd element from the collection.

operator fun <T> Array<out T>.component2(): T
Common
JVM
JS
Native
1.0

component3

Returns 3rd element from the collection.

operator fun <T> Array<out T>.component3(): T
Common
JVM
JS
Native
1.0

component4

Returns 4th element from the collection.

operator fun <T> Array<out T>.component4(): T
Common
JVM
JS
Native
1.0

component5

Returns 5th element from the collection.

operator fun <T> Array<out T>.component5(): T
Common
JVM
JS
Native
1.0

contains

Returns true if element is found in the array.

operator fun <T> Array<out T>.contains(element: T): Boolean
Common
JVM
JS
Native
1.0

count

Returns the number of elements in this array.

fun <T> Array<out T>.count(): Int

Returns the number of elements matching the given predicate.

fun <T> Array<out T>.count(predicate: (T) -> Boolean): Int
Common
JVM
JS
Native
1.0

distinct

Returns a list containing only distinct elements from the given array.

fun <T> Array<out T>.distinct(): List<T>
Common
JVM
JS
Native
1.0

distinctBy

Returns a list containing only elements from the given array having distinct keys returned by the given selector function.

fun <T, K> Array<out T>.distinctBy(
    selector: (T) -> K
): List<T>
Common
JVM
JS
Native
1.0

drop

Returns a list containing all elements except first n elements.

fun <T> Array<out T>.drop(n: Int): List<T>
Common
JVM
JS
Native
1.0

dropLast

Returns a list containing all elements except last n elements.

fun <T> Array<out T>.dropLast(n: Int): List<T>
Common
JVM
JS
Native
1.0

dropLastWhile

Returns a list containing all elements except last elements that satisfy the given predicate.

fun <T> Array<out T>.dropLastWhile(
    predicate: (T) -> Boolean
): List<T>
Common
JVM
JS
Native
1.0

dropWhile

Returns a list containing all elements except first elements that satisfy the given predicate.

fun <T> Array<out T>.dropWhile(
    predicate: (T) -> Boolean
): List<T>
Common
JVM
JS
Native
1.0

elementAt

Returns an element at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this array.

fun <T> Array<out T>.elementAt(index: Int): T
Common
JVM
JS
Native
1.0

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 array.

fun <T> Array<out T>.elementAtOrElse(
    index: Int,
    defaultValue: (Int) -> T
): T
Common
JVM
JS
Native
1.0

elementAtOrNull

Returns an element at the given index or null if the index is out of bounds of this array.

fun <T> Array<out T>.elementAtOrNull(index: Int): T?
JVM
1.0

fill

Fills original array with the provided value.

fun <T> Array<T>.fill(
    element: T,
    fromIndex: Int = 0,
    toIndex: Int = size)
Common
JVM
JS
Native
1.0

filter

Returns a list containing only elements matching the given predicate.

fun <T> Array<out T>.filter(
    predicate: (T) -> Boolean
): List<T>
Common
JVM
JS
Native
1.0

filterIndexed

Returns a list containing only elements matching the given predicate.

fun <T> Array<out T>.filterIndexed(
    predicate: (index: Int, T) -> Boolean
): List<T>
Common
JVM
JS
Native
1.0

filterIndexedTo

Appends all elements matching the given predicate to the given destination.

fun <T, C : MutableCollection<in T>> Array<out T>.filterIndexedTo(
    destination: C,
    predicate: (index: Int, T) -> Boolean
): C

filterIsInstance

Common
JVM
JS
Native
1.0

Returns a list containing all elements that are instances of specified type parameter R.

fun <R> Array<*>.filterIsInstance(): List<R>
JVM
1.0

Returns a list containing all elements that are instances of specified class.

fun <R> Array<*>.filterIsInstance(klass: Class<R>): List<R>

filterIsInstanceTo

Common
JVM
JS
Native
1.0

Appends all elements that are instances of specified type parameter R to the given destination.

fun <R, C : MutableCollection<in R>> Array<*>.filterIsInstanceTo(
    destination: C
): C
JVM
1.0

Appends all elements that are instances of specified class to the given destination.

fun <C : MutableCollection<in R>, R> Array<*>.filterIsInstanceTo(
    destination: C,
    klass: Class<R>
): C
Common
JVM
JS
Native
1.0

filterNot

Returns a list containing all elements not matching the given predicate.

fun <T> Array<out T>.filterNot(
    predicate: (T) -> Boolean
): List<T>
Common
JVM
JS
Native
1.0

filterNotNull

Returns a list containing all elements that are not null.

fun <T : Any> Array<out T?>.filterNotNull(): List<T>
Common
JVM
JS
Native
1.0

filterNotNullTo

Appends all elements that are not null to the given destination.

fun <C : MutableCollection<in T>, T : Any> Array<out T?>.filterNotNullTo(
    destination: C
): C
Common
JVM
JS
Native
1.0

filterNotTo

Appends all elements not matching the given predicate to the given destination.

fun <T, C : MutableCollection<in T>> Array<out T>.filterNotTo(
    destination: C,
    predicate: (T) -> Boolean
): C
Common
JVM
JS
Native
1.0

filterTo

Appends all elements matching the given predicate to the given destination.

fun <T, C : MutableCollection<in T>> Array<out T>.filterTo(
    destination: C,
    predicate: (T) -> Boolean
): C
Common
JVM
JS
Native
1.0

find

Returns the first element matching the given predicate, or null if no such element was found.

fun <T> Array<out T>.find(predicate: (T) -> Boolean): T?
Common
JVM
JS
Native
1.0

findLast

Returns the last element matching the given predicate, or null if no such element was found.

fun <T> Array<out T>.findLast(predicate: (T) -> Boolean): T?
Common
JVM
JS
Native
1.0

first

Returns first element.

fun <T> Array<out T>.first(): T

Returns the first element matching the given predicate.

fun <T> Array<out T>.first(predicate: (T) -> Boolean): T
Common
JVM
JS
Native
1.0

firstOrNull

Returns the first element, or null if the array is empty.

fun <T> Array<out T>.firstOrNull(): T?

Returns the first element matching the given predicate, or null if element was not found.

fun <T> Array<out T>.firstOrNull(
    predicate: (T) -> Boolean
): T?
Common
JVM
JS
Native
1.0

flatMap

Returns a single list of all elements yielded from results of transform function being invoked on each element of original array.

fun <T, R> Array<out T>.flatMap(
    transform: (T) -> Iterable<R>
): List<R>
Common
JVM
JS
Native
1.0

flatMapTo

Appends all elements yielded from results of transform function being invoked on each element of original array, to the given destination.

fun <T, R, C : MutableCollection<in R>> Array<out T>.flatMapTo(
    destination: C,
    transform: (T) -> Iterable<R>
): C
Common
JVM
JS
Native
1.0

flatten

Returns a single list of all elements from all arrays in the given array.

fun <T> Array<out Array<out T>>.flatten(): List<T>
Common
JVM
JS
Native
1.0

fold

Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element.

fun <T, R> Array<out T>.fold(
    initial: R,
    operation: (acc: R, T) -> R
): R
Common
JVM
JS
Native
1.0

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 array.

fun <T, R> Array<out T>.foldIndexed(
    initial: R,
    operation: (index: Int, acc: R, T) -> R
): R
Common
JVM
JS
Native
1.0

foldRight

Accumulates value starting with initial value and applying operation from right to left to each element and current accumulator value.

fun <T, R> Array<out T>.foldRight(
    initial: R,
    operation: (T, acc: R) -> R
): R
Common
JVM
JS
Native
1.0

foldRightIndexed

Accumulates value starting with initial value and applying operation from right to left to each element with its index in the original array and current accumulator value.

fun <T, R> Array<out T>.foldRightIndexed(
    initial: R,
    operation: (index: Int, T, acc: R) -> R
): R
Common
JVM
JS
Native
1.0

forEach

Performs the given action on each element.

fun <T> Array<out T>.forEach(action: (T) -> Unit)
Common
JVM
JS
Native
1.0

forEachIndexed

Performs the given action on each element, providing sequential index with the element.

fun <T> Array<out T>.forEachIndexed(
    action: (index: Int, T) -> Unit)
Common
JVM
JS
Native
1.0

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 array.

fun <T> Array<out T>.getOrElse(
    index: Int,
    defaultValue: (Int) -> T
): T
Common
JVM
JS
Native
1.0

getOrNull

Returns an element at the given index or null if the index is out of bounds of this array.

fun <T> Array<out T>.getOrNull(index: Int): T?
Common
JVM
JS
Native
1.0

groupBy

Groups elements of the original array 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.

fun <T, K> Array<out T>.groupBy(
    keySelector: (T) -> K
): Map<K, List<T>>

Groups values returned by the valueTransform function applied to each element of the original array 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.

fun <T, K, V> Array<out T>.groupBy(
    keySelector: (T) -> K,
    valueTransform: (T) -> V
): Map<K, List<V>>
Common
JVM
JS
Native
1.0

groupByTo

Groups elements of the original array 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.

fun <T, K, M : MutableMap<in K, MutableList<T>>> Array<out T>.groupByTo(
    destination: M,
    keySelector: (T) -> K
): M

Groups values returned by the valueTransform function applied to each element of the original array 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.

fun <T, K, V, M : MutableMap<in K, MutableList<V>>> Array<out T>.groupByTo(
    destination: M,
    keySelector: (T) -> K,
    valueTransform: (T) -> V
): M
Common
JVM
JS
Native
1.1

groupingBy

Creates a Grouping source from an array to be used later with one of group-and-fold operations using the specified keySelector function to extract a key from each element.

fun <T, K> Array<out T>.groupingBy(
    keySelector: (T) -> K
): Grouping<T, K>
Common
JVM
JS
Native
1.0

indexOf

Returns first index of element, or -1 if the array does not contain element.

fun <T> Array<out T>.indexOf(element: T): Int
Common
JVM
JS
Native
1.0

indexOfFirst

Returns index of the first element matching the given predicate, or -1 if the array does not contain such element.

fun <T> Array<out T>.indexOfFirst(
    predicate: (T) -> Boolean
): Int
Common
JVM
JS
Native
1.0

indexOfLast

Returns index of the last element matching the given predicate, or -1 if the array does not contain such element.

fun <T> Array<out T>.indexOfLast(
    predicate: (T) -> Boolean
): Int
Common
JVM
JS
Native
1.0

intersect

Returns a set containing all elements that are contained by both this set and the specified collection.

infix fun <T> Array<out T>.intersect(
    other: Iterable<T>
): Set<T>
JVM
1.0

isArrayOf

Checks if array can contain element of type T.

fun <T : Any> Array<*>.isArrayOf(): Boolean
Common
JVM
JS
Native
1.0

isEmpty

Returns true if the array is empty.

fun <T> Array<out T>.isEmpty(): Boolean
Common
JVM
JS
Native
1.0

isNotEmpty

Returns true if the array is not empty.

fun <T> Array<out T>.isNotEmpty(): Boolean
Common
JVM
JS
Native
1.3

isNullOrEmpty

Returns true if this nullable array is either null or empty.

fun Array<*>?.isNullOrEmpty(): Boolean
Common
JVM
JS
Native
1.0

joinTo

Appends the string from all the elements separated using separator and using the given prefix and postfix if supplied.

fun <T, A : Appendable> Array<out T>.joinTo(
    buffer: A,
    separator: CharSequence = ", ",
    prefix: CharSequence = "",
    postfix: CharSequence = "",
    limit: Int = -1,
    truncated: CharSequence = "...",
    transform: (T) -> CharSequence = null
): A
Common
JVM
JS
Native
1.0

joinToString

Creates a string from all the elements separated using separator and using the given prefix and postfix if supplied.

fun <T> Array<out T>.joinToString(
    separator: CharSequence = ", ",
    prefix: CharSequence = "",
    postfix: CharSequence = "",
    limit: Int = -1,
    truncated: CharSequence = "...",
    transform: (T) -> CharSequence = null
): String
Common
JVM
JS
Native
1.0

last

Returns the last element.

fun <T> Array<out T>.last(): T

Returns the last element matching the given predicate.

fun <T> Array<out T>.last(predicate: (T) -> Boolean): T
Common
JVM
JS
Native
1.0

lastIndexOf

Returns last index of element, or -1 if the array does not contain element.

fun <T> Array<out T>.lastIndexOf(element: T): Int
Common
JVM
JS
Native
1.0

lastOrNull

Returns the last element, or null if the array is empty.

fun <T> Array<out T>.lastOrNull(): T?

Returns the last element matching the given predicate, or null if no such element was found.

fun <T> Array<out T>.lastOrNull(
    predicate: (T) -> Boolean
): T?
Common
JVM
JS
Native
1.0

map

Returns a list containing the results of applying the given transform function to each element in the original array.

fun <T, R> Array<out T>.map(transform: (T) -> R): List<R>
Common
JVM
JS
Native
1.0

mapIndexed

Returns a list containing the results of applying the given transform function to each element and its index in the original array.

fun <T, R> Array<out T>.mapIndexed(
    transform: (index: Int, T) -> R
): List<R>
Common
JVM
JS
Native
1.0

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 array.

fun <T, R : Any> Array<out T>.mapIndexedNotNull(
    transform: (index: Int, T) -> R?
): List<R>
Common
JVM
JS
Native
1.0

mapIndexedNotNullTo

Applies the given transform function to each element and its index in the original array and appends only the non-null results to the given destination.

fun <T, R : Any, C : MutableCollection<in R>> Array<out T>.mapIndexedNotNullTo(
    destination: C,
    transform: (index: Int, T) -> R?
): C
Common
JVM
JS
Native
1.0

mapIndexedTo

Applies the given transform function to each element and its index in the original array and appends the results to the given destination.

fun <T, R, C : MutableCollection<in R>> Array<out T>.mapIndexedTo(
    destination: C,
    transform: (index: Int, T) -> R
): C
Common
JVM
JS
Native
1.0

mapNotNull

Returns a list containing only the non-null results of applying the given transform function to each element in the original array.

fun <T, R : Any> Array<out T>.mapNotNull(
    transform: (T) -> R?
): List<R>
Common
JVM
JS
Native
1.0

mapNotNullTo

Applies the given transform function to each element in the original array and appends only the non-null results to the given destination.

fun <T, R : Any, C : MutableCollection<in R>> Array<out T>.mapNotNullTo(
    destination: C,
    transform: (T) -> R?
): C
Common
JVM
JS
Native
1.0

mapTo

Applies the given transform function to each element of the original array and appends the results to the given destination.

fun <T, R, C : MutableCollection<in R>> Array<out T>.mapTo(
    destination: C,
    transform: (T) -> R
): C
Common
JVM
JS
Native
1.0

max

Returns the largest element or null if there are no elements.

fun <T : Comparable<T>> any_array<T>.max(): T?
Common
JVM
JS
Native
1.0

maxBy

Returns the first element yielding the largest value of the given function or null if there are no elements.

fun <T, R : Comparable<R>> Array<out T>.maxBy(
    selector: (T) -> R
): T?
Common
JVM
JS
Native
1.0

maxWith

Returns the first element having the largest value according to the provided comparator or null if there are no elements.

fun <T> Array<out T>.maxWith(
    comparator: Comparator<in T>
): T?
Common
JVM
JS
Native
1.0

min

Returns the smallest element or null if there are no elements.

fun <T : Comparable<T>> any_array<T>.min(): T?
Common
JVM
JS
Native
1.0

minBy

Returns the first element yielding the smallest value of the given function or null if there are no elements.

fun <T, R : Comparable<R>> Array<out T>.minBy(
    selector: (T) -> R
): T?
Common
JVM
JS
Native
1.0

minWith

Returns the first element having the smallest value according to the provided comparator or null if there are no elements.

fun <T> Array<out T>.minWith(
    comparator: Comparator<in T>
): T?
Common
JVM
JS
Native
1.0

none

Returns true if the array has no elements.

fun <T> Array<out T>.none(): Boolean

Returns true if no elements match the given predicate.

fun <T> Array<out T>.none(predicate: (T) -> Boolean): Boolean
Common
JVM
JS
Native
1.0

partition

Splits the original array into pair of lists, where first list contains elements for which predicate yielded true, while second list contains elements for which predicate yielded false.

fun <T> Array<out T>.partition(
    predicate: (T) -> Boolean
): Pair<List<T>, List<T>>
Native
1.3

plus

Returns an array containing all elements of the original array and then all elements of the given elements array.

operator fun <T> Array<T>.plus(elements: Array<T>): Array<T>
Common
JVM
JS
Native
1.3

random

Returns a random element from this array.

fun <T> Array<out T>.random(): T

Returns a random element from this array using the specified source of randomness.

fun <T> Array<out T>.random(random: Random): T
Common
JVM
JS
Native
1.0

reduce

Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element.

fun <S, T : S> Array<out T>.reduce(
    operation: (acc: S, T) -> S
): S
Common
JVM
JS
Native
1.0

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 array.

fun <S, T : S> Array<out T>.reduceIndexed(
    operation: (index: Int, acc: S, T) -> S
): S
Common
JVM
JS
Native
1.0

reduceRight

Accumulates value starting with last element and applying operation from right to left to each element and current accumulator value.

fun <S, T : S> Array<out T>.reduceRight(
    operation: (T, acc: S) -> S
): S
Common
JVM
JS
Native
1.0

reduceRightIndexed

Accumulates value starting with last element and applying operation from right to left to each element with its index in the original array and current accumulator value.

fun <S, T : S> Array<out T>.reduceRightIndexed(
    operation: (index: Int, T, acc: S) -> S
): S
Common
JVM
JS
Native
1.0

requireNoNulls

Returns an original collection containing all the non-null elements, throwing an IllegalArgumentException if there are any null elements.

fun <T : Any> Array<T?>.requireNoNulls(): Array<T>
Common
JVM
JS
Native
1.0

reverse

Reverses elements in the array in-place.

fun <T> Array<T>.reverse()
Common
JVM
JS
Native
1.0

reversed

Returns a list with elements in reversed order.

fun <T> Array<out T>.reversed(): List<T>
Common
JVM
JS
Native
1.0

reversedArray

Returns an array with elements of this array in reversed order.

fun <T> Array<T>.reversedArray(): Array<T>
Common
JVM
JS
Native
1.0

single

Returns the single element, or throws an exception if the array is empty or has more than one element.

fun <T> Array<out T>.single(): T

Returns the single element matching the given predicate, or throws exception if there is no or more than one matching element.

fun <T> Array<out T>.single(predicate: (T) -> Boolean): T
Common
JVM
JS
Native
1.0

singleOrNull

Returns single element, or null if the array is empty or has more than one element.

fun <T> Array<out T>.singleOrNull(): T?

Returns the single element matching the given predicate, or null if element was not found or more than one element was found.

fun <T> Array<out T>.singleOrNull(
    predicate: (T) -> Boolean
): T?
Common
JVM
JS
Native
1.0

slice

Returns a list containing elements at indices in the specified indices range.

fun <T> Array<out T>.slice(indices: IntRange): List<T>

Returns a list containing elements at specified indices.

fun <T> Array<out T>.slice(indices: Iterable<Int>): List<T>
Common
JVM
JS
Native
1.0

sliceArray

Returns an array containing elements of this array at specified indices.

fun <T> Array<T>.sliceArray(
    indices: Collection<Int>
): Array<T>

Returns a list containing elements at indices in the specified indices range.

fun <T> Array<T>.sliceArray(indices: IntRange): Array<T>

sort

JVM
1.0

Sorts a range in the array in-place.

fun <T> Array<out T>.sort(
    fromIndex: Int = 0,
    toIndex: Int = size)
JS
1.1

Sorts the array in-place according to the order specified by the given comparison function.

fun <T> Array<out T>.sort(comparison: (a: T, b: T) -> Int)
Common
JVM
JS
Native
1.0

sortBy

Sorts elements in the array in-place according to natural sort order of the value returned by specified selector function.

fun <T, R : Comparable<R>> Array<out T>.sortBy(
    selector: (T) -> R?)
Common
JVM
JS
Native
1.0

sortByDescending

Sorts elements in the array in-place descending according to natural sort order of the value returned by specified selector function.

fun <T, R : Comparable<R>> Array<out T>.sortByDescending(
    selector: (T) -> R?)
Common
JVM
JS
Native
1.0

sortDescending

Sorts elements in the array in-place descending according to their natural sort order.

fun <T : Comparable<T>> Array<out T>.sortDescending()
Common
JVM
JS
Native
1.0

sorted

Returns a list of all elements sorted according to their natural sort order.

fun <T : Comparable<T>> Array<out T>.sorted(): List<T>
Common
JVM
JS
Native
1.0

sortedArray

Returns an array with all elements of this array sorted according to their natural sort order.

fun <T : Comparable<T>> Array<T>.sortedArray(): Array<T>
Common
JVM
JS
Native
1.0

sortedArrayDescending

Returns an array with all elements of this array sorted descending according to their natural sort order.

fun <T : Comparable<T>> Array<T>.sortedArrayDescending(): Array<T>
Common
JVM
JS
Native
1.0

sortedArrayWith

Returns an array with all elements of this array sorted according the specified comparator.

fun <T> Array<out T>.sortedArrayWith(
    comparator: Comparator<in T>
): Array<out T>
Common
JVM
JS
Native
1.0

sortedBy

Returns a list of all elements sorted according to natural sort order of the value returned by specified selector function.

fun <T, R : Comparable<R>> Array<out T>.sortedBy(
    selector: (T) -> R?
): List<T>
Common
JVM
JS
Native
1.0

sortedByDescending

Returns a list of all elements sorted descending according to natural sort order of the value returned by specified selector function.

fun <T, R : Comparable<R>> Array<out T>.sortedByDescending(
    selector: (T) -> R?
): List<T>
Common
JVM
JS
Native
1.0

sortedDescending

Returns a list of all elements sorted descending according to their natural sort order.

fun <T : Comparable<T>> Array<out T>.sortedDescending(): List<T>
Common
JVM
JS
Native
1.0

sortedWith

Returns a list of all elements sorted according to the specified comparator.

fun <T> Array<out T>.sortedWith(
    comparator: Comparator<in T>
): List<T>

sortWith

JVM
1.0

Sorts the array in-place according to the order specified by the given comparator.

fun <T> Array<out T>.sortWith(comparator: Comparator<in T>)
JVM
1.0

Sorts a range in the array in-place with the given comparator.

fun <T> Array<out T>.sortWith(
    comparator: Comparator<in T>,
    fromIndex: Int = 0,
    toIndex: Int = size)
Native
1.3
fun <T> Array<out T>.sortWith(
    comparator: Comparator<in T>,
    fromIndex: Int = 0,
    toIndex: Int = size)
Native
1.1

subarrayContentToString

Returns a string representation of the contents of the subarray of the specified array as if it is List.

fun <T> Array<out T>.subarrayContentToString(
    offset: Int,
    length: Int
): String
Common
JVM
JS
Native
1.0

subtract

Returns a set containing all elements that are contained by this array and not contained by the specified collection.

infix fun <T> Array<out T>.subtract(
    other: Iterable<T>
): Set<T>
Common
JVM
JS
Native
1.0

sum

Returns the sum of all elements in the array.

fun Array<out Byte>.sum(): Int
fun Array<out Short>.sum(): Int
fun Array<out Int>.sum(): Int
fun Array<out Long>.sum(): Long
fun Array<out Float>.sum(): Float
fun Array<out Double>.sum(): Double
Common
JVM
JS
Native
1.0

sumBy

Returns the sum of all values produced by selector function applied to each element in the array.

fun <T> Array<out T>.sumBy(selector: (T) -> Int): Int
Common
JVM
JS
Native
1.0

sumByDouble

Returns the sum of all values produced by selector function applied to each element in the array.

fun <T> Array<out T>.sumByDouble(
    selector: (T) -> Double
): Double
Common
JVM
JS
Native
1.0

take

Returns a list containing first n elements.

fun <T> Array<out T>.take(n: Int): List<T>
Common
JVM
JS
Native
1.0

takeLast

Returns a list containing last n elements.

fun <T> Array<out T>.takeLast(n: Int): List<T>
Common
JVM
JS
Native
1.0

takeLastWhile

Returns a list containing last elements satisfying the given predicate.

fun <T> Array<out T>.takeLastWhile(
    predicate: (T) -> Boolean
): List<T>
Common
JVM
JS
Native
1.0

takeWhile

Returns a list containing first elements satisfying the given predicate.

fun <T> Array<out T>.takeWhile(
    predicate: (T) -> Boolean
): List<T>
Common
JVM
JS
Native
1.0

toBooleanArray

Returns an array of Boolean containing all of the elements of this generic array.

fun Array<out Boolean>.toBooleanArray(): BooleanArray
Common
JVM
JS
Native
1.0

toByteArray

Returns an array of Byte containing all of the elements of this generic array.

fun Array<out Byte>.toByteArray(): ByteArray
Common
JVM
JS
Native
1.0

toCharArray

Returns an array of Char containing all of the elements of this generic array.

fun Array<out Char>.toCharArray(): CharArray
Common
JVM
JS
Native
1.0

toCollection

Appends all elements to the given destination collection.

fun <T, C : MutableCollection<in T>> Array<out T>.toCollection(
    destination: C
): C
Native
1.3

toCStringArray

Convert this array of Kotlin strings to C array of C strings, allocating memory for the array and C strings with given AutofreeScope.

fun Array<String>.toCStringArray(
    autofreeScope: AutofreeScope
): CPointer<CPointerVar<ByteVar>>
Native
1.3

toCValues

fun <T : CPointed> Array<CPointer<T>?>.toCValues(): CValues<CPointerVar<T>>
Common
JVM
JS
Native
1.0

toDoubleArray

Returns an array of Double containing all of the elements of this generic array.

fun Array<out Double>.toDoubleArray(): DoubleArray
Common
JVM
JS
Native
1.0

toFloatArray

Returns an array of Float containing all of the elements of this generic array.

fun Array<out Float>.toFloatArray(): FloatArray
Common
JVM
JS
Native
1.0

toHashSet

Returns a HashSet of all elements.

fun <T> Array<out T>.toHashSet(): HashSet<T>
Common
JVM
JS
Native
1.0

toIntArray

Returns an array of Int containing all of the elements of this generic array.

fun Array<out Int>.toIntArray(): IntArray
Common
JVM
JS
Native
1.0

toList

Returns a List containing all elements.

fun <T> Array<out T>.toList(): List<T>
Common
JVM
JS
Native
1.0

toLongArray

Returns an array of Long containing all of the elements of this generic array.

fun Array<out Long>.toLongArray(): LongArray
Common
JVM
JS
Native
1.0

toMap

Returns a new map containing all key-value pairs from the given array of pairs.

fun <K, V> Array<out Pair<K, V>>.toMap(): Map<K, V>

Populates and returns the destination mutable map with key-value pairs from the given array of pairs.

fun <K, V, M : MutableMap<in K, in V>> Array<out Pair<K, V>>.toMap(
    destination: M
): M
Common
JVM
JS
Native
1.0

toMutableList

Returns a MutableList filled with all elements of this array.

fun <T> Array<out T>.toMutableList(): MutableList<T>
Common
JVM
JS
Native
1.0

toMutableSet

Returns a mutable set containing all distinct elements from the given array.

fun <T> Array<out T>.toMutableSet(): MutableSet<T>
Common
JVM
JS
Native
1.0

toSet

Returns a Set of all elements.

fun <T> Array<out T>.toSet(): Set<T>
Common
JVM
JS
Native
1.0

toShortArray

Returns an array of Short containing all of the elements of this generic array.

fun Array<out Short>.toShortArray(): ShortArray
JVM
1.0

toSortedSet

Returns a SortedSet of all elements.

fun <T : Comparable<T>> any_array<T>.toSortedSet(): SortedSet<T>
Common
JVM
JS
Native
1.0

union

Returns a set containing all distinct elements from both collections.

infix fun <T> Array<out T>.union(other: Iterable<T>): Set<T>
Common
JVM
JS
Native
1.0

unzip

Returns a pair of lists, where first list is built from the first values of each pair from this array, second list is built from the second values of each pair from this array.

fun <T, R> Array<out Pair<T, R>>.unzip(): Pair<List<T>, List<R>>
Common
JVM
JS
Native
1.0

withIndex

Returns a lazy Iterable of IndexedValue for each element of the original array.

fun <T> Array<out T>.withIndex(): Iterable<IndexedValue<T>>
Common
JVM
JS
Native
1.0

zip

Returns a list of pairs built from the elements of this array and the other array with the same index. The returned list has length of the shortest collection.

infix fun <T, R> Array<out T>.zip(
    other: Array<out R>
): List<Pair<T, R>>

Returns a list of values built from the elements of this array 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.

fun <T, R, V> Array<out T>.zip(
    other: Array<out R>,
    transform: (a: T, b: R) -> V
): List<V>

Returns a list of pairs built from the elements of this collection and other array with the same index. The returned list has length of the shortest collection.

infix fun <T, R> Array<out T>.zip(
    other: Iterable<R>
): List<Pair<T, R>>

Returns a list of values built from the elements of this array 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.

fun <T, R, V> Array<out T>.zip(
    other: Iterable<R>,
    transform: (a: T, b: R) -> V
): List<V>