Arrays

object Arrays

Functions

Link copied to clipboard
fun binarySearch(a: Array<Any?>, key: Any): Int

Searches the specified array for the specified object using the binary search algorithm. The array must be sorted into ascending order according to the natural ordering of its elements (as by the .sort method) prior to making this call. If it is not sorted, the results are undefined. (If the array contains elements that are not mutually comparable (for example, strings and integers), it cannot be sorted according to the natural ordering of its elements, hence results are undefined.) If the array contains multiple elements equal to the specified object, there is no guarantee which one will be found.


fun binarySearch(a: IntArray, key: Int): Int

Searches the specified array of ints for the specified value using the binary search algorithm. The array must be sorted (as by the .sort method) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specified value, there is no guarantee which one will be found.

fun binarySearch(a: Array<Any?>, fromIndex: Int, toIndex: Int, key: Any): Int

Searches a range of the specified array for the specified object using the binary search algorithm. The range must be sorted into ascending order according to the natural ordering of its elements (as by the .sort method) prior to making this call. If it is not sorted, the results are undefined. (If the range contains elements that are not mutually comparable (for example, strings and integers), it cannot be sorted according to the natural ordering of its elements, hence results are undefined.) If the range contains multiple elements equal to the specified object, there is no guarantee which one will be found.

fun binarySearch(a: FloatArray, fromIndex: Int, toIndex: Int, key: Float): Int

Searches a range of the specified array of floats for the specified value using the binary search algorithm. The range must be sorted (as by the .sort method) prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found. This method considers all NaN values to be equivalent and equal.

fun binarySearch(a: IntArray, fromIndex: Int, toIndex: Int, key: Int): Int

Searches a range of the specified array of ints for the specified value using the binary search algorithm. The range must be sorted (as by the .sort method) prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.

Link copied to clipboard
fun compare(a: CharArray, aFromIndex: Int, aToIndex: Int, b: CharArray, bFromIndex: Int, bToIndex: Int): Int

fun compare(a: IntArray, aFromIndex: Int, aToIndex: Int, b: IntArray, bFromIndex: Int, bToIndex: Int): Int

Compares two int arrays lexicographically over the specified ranges.

fun compare(a: LongArray, aFromIndex: Int, aToIndex: Int, b: LongArray, bFromIndex: Int, bToIndex: Int): Int

Compares two long arrays lexicographically over the specified ranges.

Link copied to clipboard
fun compareUnsigned(a: ByteArray, aFromIndex: Int, aToIndex: Int, b: ByteArray, bFromIndex: Int, bToIndex: Int): Int

Compares two byte arrays lexicographically over the specified ranges, numerically treating elements as unsigned.

Link copied to clipboard
fun copyOfRange(original: ByteArray, from: Int, to: Int): ByteArray

Copies the specified range of the specified array into a new array. The initial index of the range (from) must lie between zero and original.length, inclusive. The value at original[from] is placed into the initial element of the copy (unless from == original.length or from == to). Values from subsequent elements in the original array are placed into subsequent elements in the copy. The final index of the range (to), which must be greater than or equal to from, may be greater than original.length, in which case (byte)0 is placed in all elements of the copy whose index is greater than or equal to original.length - from. The length of the returned array will be to - from.

Link copied to clipboard
fun equals(a: ByteArray, aFromIndex: Int, aToIndex: Int, b: ByteArray, bFromIndex: Int, bToIndex: Int): Boolean

Returns true if the two specified arrays of bytes, over the specified ranges, are equal to one another.

fun equals(a: CharArray, aFromIndex: Int, aToIndex: Int, b: CharArray, bFromIndex: Int, bToIndex: Int): Boolean

fun equals(a: FloatArray, aFromIndex: Int, aToIndex: Int, b: FloatArray, bFromIndex: Int, bToIndex: Int): Boolean

Returns true if the two specified arrays of floats, over the specified ranges, are equal to one another.

fun equals(a: IntArray, aFromIndex: Int, aToIndex: Int, b: IntArray, bFromIndex: Int, bToIndex: Int): Boolean

ported from equals(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)

fun equals(a: LongArray, aFromIndex: Int, aToIndex: Int, b: LongArray, bFromIndex: Int, bToIndex: Int): Boolean

Returns true if the two LongArrays, over the specified ranges, are equal (i.e. they have the same length and each corresponding element is equal).

Link copied to clipboard
fun <T> fill(a: Array<T>, value: T)
fun fill(a: ByteArray, value: Byte)
fun fill(a: CharArray, value: Char)
fun fill(a: DoubleArray, value: Double)
fun fill(a: FloatArray, value: Float)
fun fill(a: IntArray, value: Int)
fun fill(a: LongArray, value: Long)
fun fill(a: ShortArray, value: Short)
fun <T> fill(a: Array<T?>, fromIndex: Int, toIndex: Int, value: T?)
fun fill(a: Array<ByteArray?>, fromIndex: Int, toIndex: Int, value: ByteArray?)
fun fill(a: Array<IntArray>, frontIndex: Int, toIndex: Int, value: IntArray)
fun fill(a: ByteArray, fromIndex: Int, toIndex: Int, value: Byte)
fun fill(a: IntArray, fromIndex: Int, toIndex: Int, value: Int)
fun fill(a: LongArray, fromIndex: Int, toIndex: Int, value: Long)
fun fill(a: ShortArray, fromIndex: Int, toIndex: Int, value: Short)

fun fill(a: FloatArray, fromIndex: Int, toIndex: Int, value: Float)

Assigns the specified float value to each element of the specified range of the specified array of floats. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be filled is empty.)

Link copied to clipboard
fun mismatch(a: ByteArray, aOffset: Int, b: ByteArray, bOffset: Int, len: Int): Int

Returns the first index i (0 ≤ i < len) for which aaOffset + i != bbOffset + i. If no such index exists, returns -1.

fun mismatch(a: IntArray, aFromIndex: Int, b: IntArray, bFromIndex: Int, len: Int): Int

Returns the first index (0 ≤ i < len) at which the elements of the two IntArrays differ, when compared over the given length starting at aFromIndex and bFromIndex respectively. Returns -1 if no mismatch is found.

fun mismatch(a: ByteArray, aFromIndex: Int, aToIndex: Int, b: ByteArray, bFromIndex: Int, bToIndex: Int): Int

Finds and returns the relative index of the first mismatch between two byte arrays over the specified ranges, otherwise return -1 if no mismatch is found. The index will be in the range of 0 (inclusive) up to the length (inclusive) of the smaller range.

fun mismatch(a: CharArray, aFromIndex: Int, aToIndex: Int, b: CharArray, bFromIndex: Int, bToIndex: Int): Int

Finds and returns the relative index of the first mismatch between two {@code char} arrays over the specified ranges, otherwise return -1 if no mismatch is found. The index will be in the range of 0 (inclusive) up to the length (inclusive) of the smaller range.

fun mismatch(a: IntArray, aFromIndex: Int, aToIndex: Int, b: IntArray, bFromIndex: Int, bToIndex: Int): Int

Finds and returns the relative index of the first mismatch between two int arrays over the specified ranges, otherwise return -1 if no mismatch is found. The index will be in the range of 0 (inclusive) up to the length (inclusive) of the smaller range.

Link copied to clipboard
fun rangeCheck(length: Int, fromIndex: Int, toIndex: Int)

Throws an IndexOutOfBoundsException if the range [fromIndex, toIndex) is invalid for an array of the given length. Throws IllegalArgumentException if fromIndex > toIndex.

Link copied to clipboard
fun <T : Comparable<T>> sort(a: Array<T>)
fun sort(a: IntArray, fromIndex: Int, toIndex: Int)
fun sort(a: LongArray, fromIndex: Int, toIndex: Int)

fun sort(a: IntArray)
fun sort(a: LongArray)

Sorts the specified array into ascending numerical order.

fun <T> sort(a: Array<out T>, c: Comparator<out T>)

Sorts the specified array of objects according to the order induced by the specified comparator. All elements in the array must be mutually comparable by the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the array).

fun <T : Comparable<T>> sort(a: Array<T>, fromIndex: Int, toIndex: Int)

Sorts the specified range of the specified array of objects into ascending order, according to the natural ordering of its elements. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.) All elements in this range must implement the Comparable interface. Furthermore, all elements in this range must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the array).

fun sort(a: FloatArray, fromIndex: Int, toIndex: Int)

Sorts the specified range of the array into ascending order. The range to be sorted extends from the index fromIndex, inclusive, to the index toIndex, exclusive. If fromIndex == toIndex, the range to be sorted is empty.

Link copied to clipboard