Kotlin - Collections FundamentalsWhich of the following is the correct syntax to declare an immutable list of integers in Kotlin?Aval numbers: MutableList<Int> = listOf(1, 2, 3)Bval numbers: List<Int> = listOf(1, 2, 3)Cval numbers: List<Int> = mutableListOf(1, 2, 3)Dval numbers: MutableList<Int> = mutableListOf(1, 2, 3)Check Answer
Step-by-Step SolutionSolution:Step 1: Identify immutable list declarationlistOf() returns an immutable List, so the type should be List.Step 2: Match type and functionMutableList requires mutableListOf(), so val numbers: List = listOf(1, 2, 3) correctly pairs List with listOf().Final Answer:val numbers: List = listOf(1, 2, 3) -> Option BQuick Check:Immutable list syntax = val List = listOf() [OK]Quick Trick: Use listOf() with List type for immutable lists [OK]Common Mistakes:MISTAKESUsing mutableListOf() with List typeDeclaring MutableList with listOf()Mixing mutable and immutable types
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