max
Returns the largest character.
Since Kotlin
1.7Throws
if the char sequence is empty.
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
// The largest and smallest elements in the array
val numbers = intArrayOf(3, 7, 2, 6)
println(numbers.max()) // 7
println(numbers.min()) // 2
val emptyArray = intArrayOf()
// max() and min() throw if the array is empty
// emptyArray.max() // will fail with NoSuchElementException
// emptyArray.min() // will fail with NoSuchElementException
// maxOrNull() and minOrNull() return null if the array is empty
println(emptyArray.maxOrNull()) // null
println(emptyArray.minOrNull()) // null
//sampleEnd
}
Deprecated
Warning since 1.4
Error since 1.5
Hidden since 1.6
Use maxOrNull instead.
Replace with
this.maxOrNull()
Content copied to clipboard