How to use switch statement with strings in Kotlin

1 Answer

0 votes
fun main() {
    val str = "Kotlin"

    when (str) {
        "Foo" -> println("Foo")
        "Wii" -> println("Wii")
        "Kotlin" -> println("Kotlin")
        "YYI" -> println("YYI")
        else -> println("No match found.")
    }
}

 
  
/*
run:
  
Kotlin

*/

 



answered Jul 1, 2025 by avibootz
...