all

inline fun CharSequence.all(predicate: (Char) -> Boolean): Boolean(source)

Returns true if all characters match the given predicate.

Note that if the char sequence contains no characters, the function returns true because there are no characters in it that do not match the predicate. See a more detailed explanation of this logic concept in "Vacuous truth" article.

Since Kotlin

1.0

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   val string = "Kotlin"
// All characters are letters
println("string.all { it.isLetter() } is ${string.all { it.isLetter() }}") // true
// Not all of them are lowercase, though
println("string.all { it.isLowerCase() } is ${string.all { it.isLowerCase() }}") // false
// And there are definitely no digits
println("string.all { it.isDigit() } is ${string.all { it.isDigit() }}") // false

// For an empty string `all` always return `true`
println("\"\".all { true } is ${"".all { true }}") // true
println("\"\".all { false } is ${"".all { false }}") // true 
   //sampleEnd
}