none

Returns true if the char sequence has no characters.

Since Kotlin

1.0

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   // none is synonymous to isEmpty()
println("\"str\".none() is ${"str".none()}") // false
println("\"\".none() is ${"".none()}") // true 
   //sampleEnd
}

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

Returns true if no characters match the given predicate.

Since Kotlin

1.0

Samples

import kotlin.test.*

fun main() { 
   //sampleStart 
   val string = "Kotlin"
// All characters are letters
println("string.none { it.isLetter() } is ${string.none { it.isLetter() }}") // false
// Some of them are lowercase letters
println("string.none { it.isLowerCase() } is ${string.none { it.isLowerCase() }}") // false
// But there are no digits among them, thus none returns true only for this predicate
println("string.none { it.isDigit() } is ${string.none { it.isDigit() }}") // true

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