Tsallaka zuwa abun ciki
Justice Tech School

Kotlin Lists

listOf creates an immutable list and mutableListOf one you can change. Common functions: add, remove, contains, first, last, sorted, reversed.

Example
val fixed = listOf(3, 1, 2)
val m = mutableListOf("a", "b")
m.add("c"); m.remove("a")
println("$fixed ${fixed.sorted()} $m ${m.size}")

Exercise

Mutable list.

Of(1, 2)

Quiz Test

Can you add to listOf?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.