Bird
0
0

Which of the following is the correct way to declare a mutable list interface in Kotlin?

easy📝 Syntax Q12 of 15
Kotlin - Collections Fundamentals
Which of the following is the correct way to declare a mutable list interface in Kotlin?
Aval list: MutableList<Int> = listOf(1, 2, 3)
Bval list: List<Int> = mutableListOf(1, 2, 3)
Cval list: MutableList<Int> = mutableListOf(1, 2, 3)
Dval list: List<Int> = listOf(1, 2, 3)
Step-by-Step Solution
Solution:
  1. Step 1: Identify mutable list declaration

    MutableList is the interface for mutable lists, and mutableListOf() creates a mutable list instance.
  2. Step 2: Check each option

    val list: MutableList = mutableListOf(1, 2, 3) correctly declares a MutableList and initializes it with mutableListOf().
  3. Final Answer:

    val list: MutableList = mutableListOf(1, 2, 3) -> Option C
  4. Quick Check:

    MutableList + mutableListOf() = mutable list [OK]
Quick Trick: Use MutableList with mutableListOf() for mutable lists [OK]
Common Mistakes:
MISTAKES
  • Using listOf() with MutableList type
  • Declaring mutable list as List type
  • Mixing mutable and immutable functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes