Introduction to Kotlin Collections

Kotlin collections classes are the same as Java collections, but you can create them differently, and they also have an API that has been enhanced with Kotlin’s extension functions.

Key: Mutable vs immutable collections

One important thing to know about Kotlin collections classes is that they’re split into two categories:

  • Mutable classes — elements can be added and removed
  • Immutable classes — their elements can’t be changed

In general I’ve found that my code is simpler if I prefer the immutable collections classes. That is, I always use an immutable class unless there’s a compelling reason not to.

results matching ""

    No results matching ""