Map Creation in Kotlin

Level 286 keystrokes

Creates a read-only map and reads a value and its size.

Kotlin code

// mapOf creates a read-only map of key-value pairs
// "Alice" to 25 uses the infix function to and creates a Pair
1val ages = mapOf("Alice" to 25, "Bob" to 30)
// [key] returns the value for that key: 25
2println(ages["Alice"])
// size returns the number of entries: 2
3println(ages.size)

Output

25
2
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.

  • "× 6
  • (× 3
  • )× 3
  • ,× 1
  • .× 1
  • [× 1
  • ]× 1
  • =× 1

More Kotlin examples at level 2

← Kotlin typing practice