isBlank
Returns true
if this char sequence is empty or consists solely of whitespace characters according to Char.isWhitespace.
Returns true
if this char sequence is empty or consists solely of whitespace characters according to Char.isWhitespace.
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 }
xxxxxxxxxx
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
Thanks for your feedback!