Returns true
if the content of this string is equal to the word "true", false
if it is equal to "false", and null
otherwise.
There is also a lenient version of the function available on nullable String, String?.toBoolean. Note that this function is case-sensitive.
Since Kotlin
1.5Samples
import java.util.Locale
import kotlin.test.*
fun main() {
println("true".toBooleanStrictOrNull())
println("True".toBooleanStrictOrNull())
println("TRUE".toBooleanStrictOrNull())
println("false".toBooleanStrictOrNull())
println("False".toBooleanStrictOrNull())
println("FALSE".toBooleanStrictOrNull())
println("abc".toBooleanStrictOrNull())
}
Target: JVMRunning on v.2.1.20