Stage 1 · Lesson 6 of 9
Collections and their operations
come in two flavours. List, Set and Map are read-only. MutableList, MutableSet and MutableMap can be changed.
Share the read-only types with the rest of the app and keep changes private to the class that owns the data. The standard library has an operation for nearly everything: map, filter, first, firstOrNull, any, sumOf, sortedBy, groupBy and associateBy.
Note the difference between sortedBy, which returns a new list, and sortBy, which sorts a mutable list in place. Operations on a List run straight away and create a new list at each step, which is fine for the amount of data a screen shows.
Common trapcalling first() on a list that may be empty, which throws; use firstOrNull() and handle null.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- GuideFreeKotlin Documentation
JetBrains
Start with the Kotlin tour, then the null safety and coroutines basics pages
- CourseFreeAndroid Basics with Compose
Google · Beginner
The Kotlin pathways in Units 1 to 3 teach the language with practice sets