Kotlin Arrays Extensions


Example

average() 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() return an item of the array

getOrNull(index: Int) returns null if index is out of bounds, otherwise an item of the array

first(), last()

toHashSet() returns a HashSet<T> of all elements

sortedArray(), sortedArrayDescending() creates and returns a new array with sorted elements of current

sort(), sortDescending sort the array in-place

min(), max()