Overview - Why immutable collections are default
What is it?
Immutable collections are collections that cannot be changed after they are created. In Kotlin, these collections are the default choice, meaning you get lists, sets, and maps that do not allow adding, removing, or modifying elements. This helps keep data safe and predictable because once created, the collection stays the same. It is like having a photo that never changes instead of a whiteboard you can erase and rewrite.
Why it matters
Making immutable collections the default prevents many common bugs caused by unexpected changes to data. Without this, programs could behave unpredictably if parts of the code change collections without others knowing. This leads to safer, easier-to-understand code and fewer errors in apps and systems. Imagine if your important notes kept changing without warning — immutable collections stop that from happening in programming.
Where it fits
Before learning this, you should understand basic collections like lists, sets, and maps in Kotlin. After this, you can explore how to work with mutable collections when changes are needed and learn about thread safety and concurrency where immutability is very helpful.