Bird
0
0

Which Kotlin function creates a list that cannot be changed after it is created?

easy📝 Conceptual Q11 of 15
Kotlin - Collections Fundamentals
Which Kotlin function creates a list that cannot be changed after it is created?
A<code>listOf</code>
B<code>mutableListOf</code>
C<code>arrayListOf</code>
D<code>setOf</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand listOf behavior

    listOf creates a fixed list that cannot be changed after creation.
  2. Step 2: Compare with mutableListOf

    mutableListOf creates a list that can be changed (add/remove items).
  3. Final Answer:

    listOf -> Option A
  4. Quick Check:

    Fixed list = listOf [OK]
Quick Trick: Use listOf for fixed lists, mutableListOf for changeable lists [OK]
Common Mistakes:
MISTAKES
  • Confusing mutableListOf as fixed list
  • Thinking arrayListOf is immutable
  • Using setOf which creates a set, not a list

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes