maxWithOrNull
Returns the first character having the largest value according to the provided comparator or null if there are no characters.
fun CharSequence.maxWithOrNull(comparator: Comparator<in Char>): Char?(source)
fun main() {
val text = "Kotlin"
// Find the character with the highest natural order value
val maxChar = text.maxWithOrNull(compareBy<Char> { it })
println(maxChar) // prints: t
// Example with an empty string – result is null
val empty = "".maxWithOrNull(compareBy<Char> { it })
println(empty) // prints: null
}