Recall & Review
beginner
What does it mean when a collection is immutable in Kotlin?
An immutable collection cannot be changed after it is created. You cannot add, remove, or update its elements.
Click to reveal answer
beginner
Why are immutable collections the default in Kotlin?
Immutable collections help avoid bugs by preventing accidental changes. They make programs safer and easier to understand.
Click to reveal answer
intermediate
How do immutable collections improve thread safety?
Since immutable collections cannot change, multiple threads can read them without conflicts or the need for locks.
Click to reveal answer
beginner
What is a real-life example to understand immutable collections?
Think of a printed book. Once printed, the pages don’t change. This is like an immutable collection where data stays the same.
Click to reveal answer
beginner
How can you create a mutable collection if needed in Kotlin?
You can use functions like mutableListOf() or mutableMapOf() to create collections that can be changed.
Click to reveal answer
What happens if you try to add an element to an immutable list in Kotlin?
✗ Incorrect
Immutable lists do not support adding elements, so Kotlin prevents this at compile time.
Why does Kotlin prefer immutable collections by default?
✗ Incorrect
Immutable collections help avoid accidental changes, making code safer and easier to maintain.
Which of these is a mutable collection in Kotlin?
✗ Incorrect
mutableListOf() creates a list that can be changed after creation.
How do immutable collections help with multi-threading?
✗ Incorrect
Immutable collections cannot change, so multiple threads can read them safely at the same time.
Which analogy best describes an immutable collection?
✗ Incorrect
A printed book is fixed and cannot be changed, just like an immutable collection.
Explain why Kotlin uses immutable collections as the default choice.
Think about how unchanging data helps avoid mistakes.
You got /4 concepts.
Describe a real-life example that helps you understand immutable collections.
Consider something you cannot change once made.
You got /3 concepts.