Kotlin When Statement

The when statement replaces Java's switch.

Kotlin introduced the when statement. Let's see an example:

        val firstName = "Daniel"

        when (firstName) {
            "Daniel" -> d("daniel", "welcome, buddy :)")
            "Mel" -> d("daniel", "welcome, Mel!")
            "Jordan" -> d("daniel", "want to grab dinner?")
        }

It can sometimes be useful for determining a given action, and an alternative to the if and switch statements.

Note: Kotlin does hot have a switch case statement.

Kotlin: val vs var

More Tutorials

Build a Ridesharing Android App - Part 1

Getting started is sometimes the hardest part.

setOnClickListener

Add a click listener in Kotlin.

Android Login Layout

Let users sign in.