WBF Academy
Collections Advanced 4 min read

Mutable vs Immutable Collections

Understand the collection mutability contract

Kotlin Academy

Kotlin Academy

Kotlin Engineer

5 months ago

In Kotlin, List is a read-only interface, not an immutable data structure — the underlying object may still be a MutableList. This distinction matters when sharing collections across threads or APIs. Call toList() to create a true snapshot copy. For persistent/immutable collections with structural sharing and O(log n) updates, use the kotlinx.collections.immutable library's persistentListOf.

#kotlin #immutability #mutable #collections