Destructuring in Kotlin

Level 262 keystrokes

Uses a destructuring declaration to unpack a Pair into two variables.

Kotlin code

// (name, age) assigns the Pair's first value to name and the second to age
1val (name, age) = Pair("Alice", 30)
// Prints Alice
2println(name)
// Prints 30
3println(age)

Output

Alice
30
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Kotlin code and how often they appear.

  • (× 4
  • )× 4
  • ,× 2
  • "× 2
  • =× 1

More Kotlin examples at level 2

← Kotlin typing practice