Collections
suggest changeIntroduction
Unlike many languages, Kotlin distinguishes between mutable and immutable collections (lists, sets, maps, etc). Precise control over exactly when collections can be edited is useful for eliminating bugs, and for designing good APIs.
Syntax
listOf,mapOf, andsetOfreturn read-only objects. You cannot add or remove items.- To add or remove items, use
arrayListOf,hashMapOf,hashSetOf,linkedMapOf(LinkedHashMap),linkedSetOf(LinkedHashSet),mutableListOf(MutableList),mutableMapOf(MutableMap),mutableSetOf(MutableSet),sortedMapOf, orsortedSetOf. - Each collection has functions such as
first(),last(), andget(), and higher-order functions such asfilter,map,joinToString, andreduce.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents