Quantcast
Viewing all articles
Browse latest Browse all 5

Answer by deHaar for starts with inside switch statement Kotlin

You can use a when without an argument:

val msg = "This is some message"when {    msg.startsWith("This") -> println("Starts with This")    msg.startsWith("That") -> println("Starts with That")    else -> println("Doesn't start with This or That")}

Output:

Starts with This

Viewing all articles
Browse latest Browse all 5

Trending Articles