Collection Types in Kotlin

From the Kotlin cheat sheet · Collections · verified Jul 2026

Collection Types

Lists, Sets, and Maps

kotlin
// Immutable collections
val list = listOf(1, 2, 3)
val set = setOf("a", "b", "c")
val map = mapOf("key1" to "value1", "key2" to "value2")

// Mutable collections
val mutableList = mutableListOf(1, 2, 3)
mutableList.add(4)
mutableList.removeAt(0)

val mutableSet = mutableSetOf("a", "b")
mutableSet.add("c")

val mutableMap = mutableMapOf<String, Int>()
mutableMap["one"] = 1
mutableMap["two"] = 2

// Array types
val intArray = intArrayOf(1, 2, 3)
val stringArray = arrayOf("a", "b", "c")
val nullArray = arrayOfNulls<String>(5)
💡 Default collections are immutable, use mutable* for mutability
⚡ to infix function creates Pair for map entries
📌 buildList/buildMap efficiently create immutable collections
🟢 Arrays have fixed size, Lists can be resized (if mutable)

Continue with Kotlin

Save the full cheat sheet or work through every related task.

More Kotlin tasks

Back to the full Kotlin cheat sheet