Returns the largest element or null
if the array is empty.
If any of elements is NaN
, this function returns NaN
.
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 largest element or null
if the array is empty.
If there are multiple equal maximal elements, this function returns the first of those elements.
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
Returns the largest element or null
if the array is empty.
Since Kotlin
1.4Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
val numbers = intArrayOf(3, 7, 2, 6)
println(numbers.max())
println(numbers.min())
val emptyArray = intArrayOf()
println(emptyArray.maxOrNull())
println(emptyArray.minOrNull())
}
Target: JVMRunning on v.2.1.20
Returns the largest element or null
if the collection is empty.
If any of elements is NaN
, this function returns NaN
.
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 largest element or null
if the collection is empty.
If there are multiple equal maximal elements, this function returns the first of those elements.
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