Mutable List in Kotlin

Level 289 keystrokes

Creates a mutable list, adds and removes elements, and prints the result.

Kotlin code

// mutableListOf creates a list whose contents can change
1val nums = mutableListOf(1, 2, 3)
// add appends 4 at the end: [1, 2, 3, 4]
2nums.add(4)
// removeAt(0) removes the element at index 0: [2, 3, 4]
3nums.removeAt(0)
// Prints 2, 3 and 4, one per line
4for (n in nums) println(n)

Output

2
3
4
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.

  • (× 5
  • )× 5
  • ,× 2
  • .× 2
  • =× 1

More Kotlin examples at level 2

← Kotlin typing practice