W3cubDocs

/Kotlin

ShortArray

class ShortArray

An array of shorts. When targeting the JVM, instances of this class are represented as short[].

Constructors

<init>

ShortArray(size: Int, init: (Int) -> Short)

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

ShortArray(size: Int)

Creates a new array of the specified size, with all elements initialized to zero.

Properties

size

val size: Int

Returns the number of elements in the array.

Functions

get

operator fun get(index: Int): Short

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

iterator

operator fun iterator(): ShortIterator

Creates an iterator over the elements of the array.

set

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

Sets the element at the given index to the given value. This method can be called using the index operator.

Inherited Functions

equals

open operator fun equals(other: Any?): Boolean

Indicates whether some other object is "equal to" this one. Implementations must fulfil the following requirements:

hashCode

open fun hashCode(): Int

Returns a hash code value for the object. The general contract of hashCode is:

toString

open fun toString(): String

Returns a string representation of the object.

Extension Properties

indices

val ShortArray.indices: IntRange

Returns the range of valid indices for the array.

lastIndex

val ShortArray.lastIndex: Int

Returns the last valid index for the array.

Extension Functions

all

fun ShortArray.all(predicate: (Short) -> Boolean): Boolean

Returns true if all elements match the given predicate.

any

fun ShortArray.any(): Boolean

Returns true if array has at least one element.

fun ShortArray.any(predicate: (Short) -> Boolean): Boolean

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

asIterable

fun ShortArray.asIterable(): Iterable<Short>

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

asList

fun ShortArray.asList(): List<Short>

Returns a List that wraps the original array.

asSequence

fun ShortArray.asSequence(): Sequence<Short>

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

associate

fun <K, V> ShortArray.associate(
    transform: (Short) -> Pair<K, V>
): Map<K, V>

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

associateBy

fun <K> ShortArray.associateBy(
    keySelector: (Short) -> K
): Map<K, Short>

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

fun <K, V> ShortArray.associateBy(
    keySelector: (Short) -> K, 
    valueTransform: (Short) -> V
): Map<K, V>

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

associateByTo

fun <K, M : MutableMap<in K, in Short>> ShortArray.associateByTo(
    destination: M, 
    keySelector: (Short) -> K
): M

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, V, M : MutableMap<in K, in V>> ShortArray.associateByTo(
    destination: M, 
    keySelector: (Short) -> K, 
    valueTransform: (Short) -> V
): 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.

associateTo

fun <K, V, M : MutableMap<in K, in V>> ShortArray.associateTo(
    destination: M, 
    transform: (Short) -> Pair<K, V>
): M

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

average

fun ShortArray.average(): Double

Returns an average value of elements in the array.

binarySearch

fun ShortArray.binarySearch(
    element: Short, 
    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.

component1

operator fun ShortArray.component1(): Short

Returns 1st element from the collection.

component2

operator fun ShortArray.component2(): Short

Returns 2nd element from the collection.

component3

operator fun ShortArray.component3(): Short

Returns 3rd element from the collection.

component4

operator fun ShortArray.component4(): Short

Returns 4th element from the collection.

component5

operator fun ShortArray.component5(): Short

Returns 5th element from the collection.

contains

operator fun ShortArray.contains(element: Short): Boolean

Returns true if element is found in the array.

contentEquals

infix fun ShortArray.contentEquals(
    other: ShortArray
): Boolean

Returns true if the two specified arrays are structurally equal to one another, i.e. contain the same number of the same elements in the same order.

contentHashCode

fun ShortArray.contentHashCode(): Int

Returns a hash code based on the contents of this array as if it is List.

contentToString

fun ShortArray.contentToString(): String

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

copyOf

fun ShortArray.copyOf(): ShortArray

Returns new array which is a copy of the original array.

fun ShortArray.copyOf(newSize: Int): ShortArray

Returns new array which is a copy of the original array, resized to the given newSize.

copyOfRange

fun ShortArray.copyOfRange(
    fromIndex: Int, 
    toIndex: Int
): ShortArray

Returns new array which is a copy of range of original array.

count

fun ShortArray.count(): Int

Returns the number of elements in this array.

fun ShortArray.count(predicate: (Short) -> Boolean): Int

Returns the number of elements matching the given predicate.

distinct

fun ShortArray.distinct(): List<Short>

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

distinctBy

fun <K> ShortArray.distinctBy(
    selector: (Short) -> K
): List<Short>

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

drop

fun ShortArray.drop(n: Int): List<Short>

Returns a list containing all elements except first n elements.

dropLast

fun ShortArray.dropLast(n: Int): List<Short>

Returns a list containing all elements except last n elements.

dropLastWhile

fun ShortArray.dropLastWhile(
    predicate: (Short) -> Boolean
): List<Short>

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

dropWhile

fun ShortArray.dropWhile(
    predicate: (Short) -> Boolean
): List<Short>

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

elementAt

fun ShortArray.elementAt(index: Int): Short

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

elementAtOrElse

fun ShortArray.elementAtOrElse(
    index: Int, 
    defaultValue: (Int) -> Short
): Short

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.

elementAtOrNull

fun ShortArray.elementAtOrNull(index: Int): Short?

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

fill

fun ShortArray.fill(
    element: Short, 
    fromIndex: Int = 0, 
    toIndex: Int = size)

Fills original array with the provided value.

filter

fun ShortArray.filter(
    predicate: (Short) -> Boolean
): List<Short>

Returns a list containing only elements matching the given predicate.

filterIndexed

fun ShortArray.filterIndexed(
    predicate: (index: Int, Short) -> Boolean
): List<Short>

Returns a list containing only elements matching the given predicate.

filterIndexedTo

fun <C : MutableCollection<in Short>> ShortArray.filterIndexedTo(
    destination: C, 
    predicate: (index: Int, Short) -> Boolean
): C

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

filterNot

fun ShortArray.filterNot(
    predicate: (Short) -> Boolean
): List<Short>

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

filterNotTo

fun <C : MutableCollection<in Short>> ShortArray.filterNotTo(
    destination: C, 
    predicate: (Short) -> Boolean
): C

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

filterTo

fun <C : MutableCollection<in Short>> ShortArray.filterTo(
    destination: C, 
    predicate: (Short) -> Boolean
): C

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

find

fun ShortArray.find(predicate: (Short) -> Boolean): Short?

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

findLast

fun ShortArray.findLast(
    predicate: (Short) -> Boolean
): Short?

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

first

fun ShortArray.first(): Short

Returns first element.

fun ShortArray.first(predicate: (Short) -> Boolean): Short

Returns the first element matching the given predicate.

firstOrNull

fun ShortArray.firstOrNull(): Short?

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

fun ShortArray.firstOrNull(
    predicate: (Short) -> Boolean
): Short?

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

flatMap

fun <R> ShortArray.flatMap(
    transform: (Short) -> Iterable<R>
): List<R>

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

flatMapTo

fun <R, C : MutableCollection<in R>> ShortArray.flatMapTo(
    destination: C, 
    transform: (Short) -> Iterable<R>
): C

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

fold

fun <R> ShortArray.fold(
    initial: R, 
    operation: (acc: R, Short) -> R
): R

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

foldIndexed

fun <R> ShortArray.foldIndexed(
    initial: R, 
    operation: (index: Int, acc: R, Short) -> R
): R

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.

foldRight

fun <R> ShortArray.foldRight(
    initial: R, 
    operation: (Short, acc: R) -> R
): R

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

foldRightIndexed

fun <R> ShortArray.foldRightIndexed(
    initial: R, 
    operation: (index: Int, Short, acc: R) -> R
): R

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.

forEach

fun ShortArray.forEach(action: (Short) -> Unit)

Performs the given action on each element.

forEachIndexed

fun ShortArray.forEachIndexed(
    action: (index: Int, Short) -> Unit)

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

getOrElse

fun ShortArray.getOrElse(
    index: Int, 
    defaultValue: (Int) -> Short
): Short

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.

getOrNull

fun ShortArray.getOrNull(index: Int): Short?

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

groupBy

fun <K> ShortArray.groupBy(
    keySelector: (Short) -> K
): Map<K, List<Short>>

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 <K, V> ShortArray.groupBy(
    keySelector: (Short) -> K, 
    valueTransform: (Short) -> V
): Map<K, List<V>>

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

fun <K, M : MutableMap<in K, MutableList<Short>>> ShortArray.groupByTo(
    destination: M, 
    keySelector: (Short) -> K
): M

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, V, M : MutableMap<in K, MutableList<V>>> ShortArray.groupByTo(
    destination: M, 
    keySelector: (Short) -> K, 
    valueTransform: (Short) -> V
): 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.

indexOf

fun ShortArray.indexOf(element: Short): Int

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

indexOfFirst

fun ShortArray.indexOfFirst(
    predicate: (Short) -> Boolean
): Int

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

indexOfLast

fun ShortArray.indexOfLast(
    predicate: (Short) -> Boolean
): Int

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

intersect

infix fun ShortArray.intersect(
    other: Iterable<Short>
): Set<Short>

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

isEmpty

fun ShortArray.isEmpty(): Boolean

Returns true if the array is empty.

isNotEmpty

fun ShortArray.isNotEmpty(): Boolean

Returns true if the array is not empty.

joinTo

fun <A> ShortArray.joinTo(
    buffer: A, 
    separator: CharSequence = ", ", 
    prefix: CharSequence = "", 
    postfix: CharSequence = "", 
    limit: Int = -1, 
    truncated: CharSequence = "...", 
    transform: (Short) -> CharSequence = null
): A

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

joinToString

fun ShortArray.joinToString(
    separator: CharSequence = ", ", 
    prefix: CharSequence = "", 
    postfix: CharSequence = "", 
    limit: Int = -1, 
    truncated: CharSequence = "...", 
    transform: (Short) -> CharSequence = null
): String

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

last

fun ShortArray.last(): Short

Returns the last element.

fun ShortArray.last(predicate: (Short) -> Boolean): Short

Returns the last element matching the given predicate.

lastIndexOf

fun ShortArray.lastIndexOf(element: Short): Int

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

lastOrNull

fun ShortArray.lastOrNull(): Short?

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

fun ShortArray.lastOrNull(
    predicate: (Short) -> Boolean
): Short?

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

map

fun <R> ShortArray.map(transform: (Short) -> R): List<R>

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

mapIndexed

fun <R> ShortArray.mapIndexed(
    transform: (index: Int, Short) -> R
): List<R>

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

mapIndexedTo

fun <R, C : MutableCollection<in R>> ShortArray.mapIndexedTo(
    destination: C, 
    transform: (index: Int, Short) -> R
): C

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

mapTo

fun <R, C : MutableCollection<in R>> ShortArray.mapTo(
    destination: C, 
    transform: (Short) -> R
): C

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

max

fun ShortArray.max(): Short?

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

maxBy

fun <R : Comparable<R>> ShortArray.maxBy(
    selector: (Short) -> R
): Short?

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

maxWith

fun ShortArray.maxWith(
    comparator: Comparator<in Short>
): Short?
fun ShortArray.maxWith(
    comparator: Comparator<in Short>
): Short?

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

min

fun ShortArray.min(): Short?

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

minBy

fun <R : Comparable<R>> ShortArray.minBy(
    selector: (Short) -> R
): Short?

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

minWith

fun ShortArray.minWith(
    comparator: Comparator<in Short>
): Short?
fun ShortArray.minWith(
    comparator: Comparator<in Short>
): Short?

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

none

fun ShortArray.none(): Boolean

Returns true if the array has no elements.

fun ShortArray.none(predicate: (Short) -> Boolean): Boolean

Returns true if no elements match the given predicate.

partition

fun ShortArray.partition(
    predicate: (Short) -> Boolean
): Pair<List<Short>, List<Short>>

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.

plus

operator fun ShortArray.plus(element: Short): ShortArray

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

operator fun ShortArray.plus(
    elements: Collection<Short>
): ShortArray

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

operator fun ShortArray.plus(
    elements: ShortArray
): ShortArray

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

reduce

fun ShortArray.reduce(
    operation: (acc: Short, Short) -> Short
): Short

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

reduceIndexed

fun ShortArray.reduceIndexed(
    operation: (index: Int, acc: Short, Short) -> Short
): Short

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.

reduceRight

fun ShortArray.reduceRight(
    operation: (Short, acc: Short) -> Short
): Short

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

reduceRightIndexed

fun ShortArray.reduceRightIndexed(
    operation: (index: Int, Short, acc: Short) -> Short
): Short

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.

reverse

fun ShortArray.reverse()

Reverses elements in the array in-place.

reversed

fun ShortArray.reversed(): List<Short>

Returns a list with elements in reversed order.

reversedArray

fun ShortArray.reversedArray(): ShortArray

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

single

fun ShortArray.single(): Short

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

fun ShortArray.single(predicate: (Short) -> Boolean): Short

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

singleOrNull

fun ShortArray.singleOrNull(): Short?

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

fun ShortArray.singleOrNull(
    predicate: (Short) -> Boolean
): Short?

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

slice

fun ShortArray.slice(indices: IntRange): List<Short>

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

fun ShortArray.slice(indices: Iterable<Int>): List<Short>

Returns a list containing elements at specified indices.

sliceArray

fun ShortArray.sliceArray(
    indices: Collection<Int>
): ShortArray

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

fun ShortArray.sliceArray(indices: IntRange): ShortArray

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

sort

fun ShortArray.sort()

Sorts the array in-place.

fun ShortArray.sort(fromIndex: Int = 0, toIndex: Int = size)

Sorts a range in the array in-place.

fun ShortArray.sort(comparison: (a: Short, b: Short) -> Int)

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

sortDescending

fun ShortArray.sortDescending()

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

sorted

fun ShortArray.sorted(): List<Short>

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

sortedArray

fun ShortArray.sortedArray(): ShortArray

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

sortedArrayDescending

fun ShortArray.sortedArrayDescending(): ShortArray

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

sortedBy

fun <R : Comparable<R>> ShortArray.sortedBy(
    selector: (Short) -> R?
): List<Short>

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

sortedByDescending

fun <R : Comparable<R>> ShortArray.sortedByDescending(
    selector: (Short) -> R?
): List<Short>

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

sortedDescending

fun ShortArray.sortedDescending(): List<Short>

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

sortedWith

fun ShortArray.sortedWith(
    comparator: Comparator<in Short>
): List<Short>
fun ShortArray.sortedWith(
    comparator: Comparator<in Short>
): List<Short>

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

subtract

infix fun ShortArray.subtract(
    other: Iterable<Short>
): Set<Short>

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

sum

fun ShortArray.sum(): Int

Returns the sum of all elements in the array.

sumBy

fun ShortArray.sumBy(selector: (Short) -> Int): Int

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

sumByDouble

fun ShortArray.sumByDouble(
    selector: (Short) -> Double
): Double

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

take

fun ShortArray.take(n: Int): List<Short>

Returns a list containing first n elements.

takeLast

fun ShortArray.takeLast(n: Int): List<Short>

Returns a list containing last n elements.

takeLastWhile

fun ShortArray.takeLastWhile(
    predicate: (Short) -> Boolean
): List<Short>

Returns a list containing last elements satisfying the given predicate.

takeWhile

fun ShortArray.takeWhile(
    predicate: (Short) -> Boolean
): List<Short>

Returns a list containing first elements satisfying the given predicate.

toCollection

fun <C : MutableCollection<in Short>> ShortArray.toCollection(
    destination: C
): C

Appends all elements to the given destination collection.

toHashSet

fun ShortArray.toHashSet(): HashSet<Short>

Returns a HashSet of all elements.

toList

fun ShortArray.toList(): List<Short>

Returns a List containing all elements.

toMutableList

fun ShortArray.toMutableList(): MutableList<Short>

Returns a MutableList filled with all elements of this array.

toMutableSet

fun ShortArray.toMutableSet(): MutableSet<Short>

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

toSet

fun ShortArray.toSet(): Set<Short>

Returns a Set of all elements.

toSortedSet

fun ShortArray.toSortedSet(): SortedSet<Short>

Returns a SortedSet of all elements.

toTypedArray

fun ShortArray.toTypedArray(): Array<Short>

Returns a typed object array containing all of the elements of this primitive array.

union

infix fun ShortArray.union(
    other: Iterable<Short>
): Set<Short>

Returns a set containing all distinct elements from both collections.

withIndex

fun ShortArray.withIndex(): Iterable<IndexedValue<Short>>

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

zip

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

Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection.

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

Returns a list of values built from elements of both collections with same indexes using provided transform. List has length of shortest collection.

© 2010–2018 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-short-array/index.html