mutableListOf, mutableMapOf: Mutable Builders
Create mutable collections and modify them safely.
When You Need Mutation
Mutable collections allow adding, removing, and updating elements. Use them when the collection grows or changes over time.
mutableListOf
mutableListOf creates a MutableList backed by ArrayList. You can add, remove, and replace elements.
val list = mutableListOf("a", "b", "c")
list.add("d")
list.add(0, "z") // insert at index 0
list.remove("b")
println(list) // [z, a, c, d]All lessons in this course
- listOf, setOf, mapOf: Read-Only Collections
- mutableListOf, mutableMapOf: Mutable Builders
- Accessing Elements: get, first, last, getOrNull
- Iterating and Transforming Collections with Standard Library