IntArray
An array of ints. When targeting the JVM, instances of this class are represented as int[]
.
Constructors
Properties
size
Returns the number of elements in the array.
val size: Int
Functions
get
Returns the array element at the given index. This method can be called using the index operator.
operator fun get(index: Int): Int
iterator
Creates an iterator over the elements of the array.
operator fun iterator(): IntIterator
Extension Properties
Extension Functions
associateBy
Returns a Map containing the elements from the given array indexed by the key returned from keySelector function applied to each element.
Returns a Map containing the values provided by valueTransform and indexed by keySelector functions applied to elements of the given array.
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 <K, M : MutableMap<in K, in Int>> IntArray.associateByTo(
destination: M,
keySelector: (Int) -> 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 <K, V, M : MutableMap<in K, in V>> IntArray.associateByTo(
destination: M,
keySelector: (Int) -> K,
valueTransform: (Int) -> 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 array.
fun <K, V, M : MutableMap<in K, in V>> IntArray.associateTo(
destination: M,
transform: (Int) -> Pair<K, V>
): M
component1
Returns 1st element from the array.
operator fun IntArray.component1(): Int
component2
Returns 2nd element from the array.
operator fun IntArray.component2(): Int
component3
Returns 3rd element from the array.
operator fun IntArray.component3(): Int
component4
Returns 4th element from the array.
operator fun IntArray.component4(): Int
component5
Returns 5th element from the array.
operator fun IntArray.component5(): Int
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 IntArray.elementAtOrElse(
index: Int,
defaultValue: (Int) -> Int
): Int
filterIndexedTo
Appends all elements matching the given predicate to the given destination.
fun <C : MutableCollection<in Int>> IntArray.filterIndexedTo(
destination: C,
predicate: (index: Int, Int) -> Boolean
): C
filterNotTo
Appends all elements not matching the given predicate to the given destination.
fun <C : MutableCollection<in Int>> IntArray.filterNotTo(
destination: C,
predicate: (Int) -> Boolean
): C
filterTo
Appends all elements matching the given predicate to the given destination.
fun <C : MutableCollection<in Int>> IntArray.filterTo(
destination: C,
predicate: (Int) -> Boolean
): C
firstOrNull
Returns the first element, or null
if the array is empty.
fun IntArray.firstOrNull(): Int?
flatMapTo
Appends all elements yielded from results of transform function being invoked on each element of original array, to the given destination.
fun <R, C : MutableCollection<in R>> IntArray.flatMapTo(
destination: C,
transform: (Int) -> Iterable<R>
): C
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 IntArray.getOrElse(
index: Int,
defaultValue: (Int) -> Int
): Int
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.
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.
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 <K, M : MutableMap<in K, MutableList<Int>>> IntArray.groupByTo(
destination: M,
keySelector: (Int) -> 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 <K, V, M : MutableMap<in K, MutableList<V>>> IntArray.groupByTo(
destination: M,
keySelector: (Int) -> K,
valueTransform: (Int) -> V
): M
isNotEmpty
Returns true
if the array is not empty.
fun IntArray.isNotEmpty(): Boolean
joinTo
Appends the string from all the elements separated using separator and using the given prefix and postfix if supplied.
fun <A : Appendable> IntArray.joinTo(
buffer: A,
separator: CharSequence = ", ",
prefix: CharSequence = "",
postfix: CharSequence = "",
limit: Int = -1,
truncated: CharSequence = "...",
transform: ((Int) -> CharSequence)? = null
): A
joinToString
Creates a string from all the elements separated using separator and using the given prefix and postfix if supplied.
fun IntArray.joinToString(
separator: CharSequence = ", ",
prefix: CharSequence = "",
postfix: CharSequence = "",
limit: Int = -1,
truncated: CharSequence = "...",
transform: ((Int) -> CharSequence)? = null
): String
lastOrNull
Returns the last element, or null
if the array is empty.
fun IntArray.lastOrNull(): Int?
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 <R, C : MutableCollection<in R>> IntArray.mapIndexedTo(
destination: C,
transform: (index: Int, Int) -> R
): C
mapTo
Applies the given transform function to each element of the original array and appends the results to the given destination.
fun <R, C : MutableCollection<in R>> IntArray.mapTo(
destination: C,
transform: (Int) -> R
): C
maxBy
Returns the first element yielding the largest value of the given function or null
if there are no elements.
fun <R : Comparable<R>> IntArray.maxBy(
selector: (Int) -> R
): Int?
maxWith
Returns the first element having the largest value according to the provided comparator or null
if there are no elements.
fun IntArray.maxWith(comparator: Comparator<in Int>): Int?
minBy
Returns the first element yielding the smallest value of the given function or null
if there are no elements.
fun <R : Comparable<R>> IntArray.minBy(
selector: (Int) -> R
): Int?
minWith
Returns the first element having the smallest value according to the provided comparator or null
if there are no elements.
fun IntArray.minWith(comparator: Comparator<in Int>): Int?
randomOrNull
Returns a random element from this array, or null
if this array is empty.
fun IntArray.randomOrNull(): Int?
refTo
fun IntArray.refTo(index: Int): CValuesRef<IntVar>
scanIndexed
scanReduceIndexed
Returns a list containing successive accumulation values generated by applying operation from left to right to each element, its index in the original array and current accumulator value that starts with the first element of this array.
single
Returns the single element, or throws an exception if the array is empty or has more than one element.
fun IntArray.single(): Int
singleOrNull
Returns single element, or null
if the array is empty or has more than one element.
fun IntArray.singleOrNull(): Int?
sliceArray
Returns an array containing elements of this array at specified indices.
fun IntArray.sliceArray(indices: Collection<Int>): IntArray
sort
Sorts a range in the array in-place.
fun IntArray.sort(fromIndex: Int = 0, toIndex: Int = size)
Sorts the array in-place according to the order specified by the given comparison function.
fun IntArray.sort(comparison: (a: Int, b: Int) -> Int)
sortDescending
Sorts elements in the array in-place descending according to their natural sort order.
fun IntArray.sortDescending()
sortedBy
Returns a list of all elements sorted according to natural sort order of the value returned by specified selector function.
fun <R : Comparable<R>> IntArray.sortedBy(
selector: (Int) -> R?
): List<Int>
sortedByDescending
Returns a list of all elements sorted descending according to natural sort order of the value returned by specified selector function.
fun <R : Comparable<R>> IntArray.sortedByDescending(
selector: (Int) -> R?
): List<Int>
sortedWith
Returns a list of all elements sorted according to the specified comparator.
fun IntArray.sortedWith(
comparator: Comparator<in Int>
): List<Int>
toCollection
Appends all elements to the given destination collection.
fun <C : MutableCollection<in Int>> IntArray.toCollection(
destination: C
): C
toMutableList
Returns a MutableList filled with all elements of this array.
fun IntArray.toMutableList(): MutableList<Int>
toMutableSet
Returns a mutable set containing all distinct elements from the given array.
fun IntArray.toMutableSet(): MutableSet<Int>
withIndex
Returns a lazy Iterable that wraps each element of the original array into an IndexedValue containing the index of that element and the element itself.
fun IntArray.withIndex(): Iterable<IndexedValue<Int>>
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.
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.
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.
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.