isBlank

Since Kotlin

1.0

Returns true if this string is empty or consists solely of whitespace characters.

Since Kotlin

1.1

Samples

import java.util.Locale
import kotlin.test.*

fun main() { 
   //sampleStart 
   fun validateName(name: String): String {
    if (name.isBlank()) throw IllegalArgumentException("Name cannot be blank")
    return name
}

println(validateName("Adam")) // Adam
// validateName("") // will fail
// validateName("  \t\n") // will fail 
   //sampleEnd
}

Returns true if this string is empty or consists solely of whitespace characters.

Since Kotlin

1.0

Samples

import java.util.Locale
import kotlin.test.*

fun main() { 
   //sampleStart 
   fun validateName(name: String): String {
    if (name.isBlank()) throw IllegalArgumentException("Name cannot be blank")
    return name
}

println(validateName("Adam")) // Adam
// validateName("") // will fail
// validateName("  \t\n") // will fail 
   //sampleEnd
}

Returns true if this string is empty or consists solely of whitespace characters.

Since Kotlin

1.3

Samples

import java.util.Locale
import kotlin.test.*

fun main() { 
   //sampleStart 
   fun validateName(name: String): String {
    if (name.isBlank()) throw IllegalArgumentException("Name cannot be blank")
    return name
}

println(validateName("Adam")) // Adam
// validateName("") // will fail
// validateName("  \t\n") // will fail 
   //sampleEnd
}

Returns true if this string is empty or consists solely of whitespace characters.

Since Kotlin

1.8

Samples

import java.util.Locale
import kotlin.test.*

fun main() { 
   //sampleStart 
   fun validateName(name: String): String {
    if (name.isBlank()) throw IllegalArgumentException("Name cannot be blank")
    return name
}

println(validateName("Adam")) // Adam
// validateName("") // will fail
// validateName("  \t\n") // will fail 
   //sampleEnd
}

Returns true if this string is empty or consists solely of whitespace characters.

Since Kotlin

1.8

Samples

import java.util.Locale
import kotlin.test.*

fun main() { 
   //sampleStart 
   fun validateName(name: String): String {
    if (name.isBlank()) throw IllegalArgumentException("Name cannot be blank")
    return name
}

println(validateName("Adam")) // Adam
// validateName("") // will fail
// validateName("  \t\n") // will fail 
   //sampleEnd
}