Extensions
suggest changeaverage() is defined for Byte, Int, Long, Short, Double, Float and always returns Double:
val doubles = doubleArrayOf(1.5, 3.0)
print(doubles.average()) // prints 2.25
val ints = intArrayOf(1, 4)
println(ints.average()) // prints 2.5
component1(), component2(), … component5() each return one item of the array.
getOrNull(index: Int) returns null if index is out of bounds, otherwise the item at that index.
first() and last() return the first and last items. They throw if the array is empty.
toHashSet() returns a HashSet<T> of all elements.
sortedArray() and sortedArrayDescending() return a new array with the elements sorted.
sort() and sortDescending() sort the array in place.
min() and max() return the smallest and largest element, or null if the array is empty. (minOrNull() and maxOrNull() are the current names.)
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents