minOrNull

Returns the smallest character or null if the char sequence is empty.

Since Kotlin

1.4

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
}