Kotlin - Collections FundamentalsWhich 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)Check Answer
Step-by-Step SolutionSolution:Step 1: Identify mutable list declarationMutableList is the interface for mutable lists, and mutableListOf() creates a mutable list instance.Step 2: Check each optionval list: MutableList = mutableListOf(1, 2, 3) correctly declares a MutableList and initializes it with mutableListOf().Final Answer:val list: MutableList = mutableListOf(1, 2, 3) -> Option CQuick Check:MutableList + mutableListOf() = mutable list [OK]Quick Trick: Use MutableList with mutableListOf() for mutable lists [OK]Common Mistakes:MISTAKESUsing listOf() with MutableList typeDeclaring mutable list as List typeMixing mutable and immutable functions
Master "Collections Fundamentals" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Collections Fundamentals - Iterating collections with forEach - Quiz 1easy Collections Fundamentals - Destructuring in collection iteration - Quiz 14medium Collections Fundamentals - Iterating collections with forEach - Quiz 3easy Data Types - Number literal formats (underscore, hex, binary) - Quiz 11easy Data Types - Why Kotlin has no primitive types at source level - Quiz 10hard Data Types - Boolean type and logical operators - Quiz 15hard Loops and Ranges - Labeled break and continue - Quiz 3easy Loops and Ranges - For loop with ranges - Quiz 14medium Null Safety - Elvis operator (?:) for default values - Quiz 14medium Operators and Expressions - Operator overloading concept - Quiz 1easy