Returns the smallest element or null
if the sequence is empty.
If any of elements is NaN
, this function returns NaN
.
The operation is terminal.
Since Kotlin
1.4Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
val numbers = doubleArrayOf(3.0, 7.2, 2.4, 6.5)
println(numbers.max())
println(numbers.min())
val numbersWithNaN = doubleArrayOf(3.0, Double.NaN, 7.2, 2.4, 6.5)
println(numbersWithNaN.max())
println(numbersWithNaN.min())
val emptyArray = doubleArrayOf()
println(emptyArray.maxOrNull())
println(emptyArray.minOrNull())
}
Target: JVMRunning on v.2.1.20
Returns the smallest element or null
if the sequence is empty.
If there are multiple equal minimal elements, this function returns the first of those elements.
The operation is terminal.
Since Kotlin
1.4Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
val names = listOf("Alice", "Bob", "Carol")
println(names.max())
println(names.min())
val emptyList = emptyList<Int>()
println(emptyList.maxOrNull())
println(emptyList.minOrNull())
}
Target: JVMRunning on v.2.1.20