Kotlin - Null SafetyWhich of the following is the correct syntax to declare a mutable list that can hold null strings in Kotlin?Aval list = mutableListOf<String>()?Bval list = mutableListOf<String?>()Cval list = mutableListOf<?String>()Dval list = mutableListOf<String?>?()Check Answer
Step-by-Step SolutionSolution:Step 1: Understand Kotlin syntax for nullable typesTo allow null elements, the element type must be nullable, written as String?.Step 2: Check correct mutable list declarationmutableListOf() correctly declares a mutable list that can hold null strings.Final Answer:val list = mutableListOf() -> Option BQuick Check:Nullable element type inside mutableListOf = correct syntax [OK]Quick Trick: Put ? after element type, not after mutableListOf [OK]Common Mistakes:MISTAKESPlacing ? after mutableListOf instead of element typeUsing invalid syntax like Adding ? after the whole expression incorrectly
Master "Null Safety" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Collections Fundamentals - Collection size and emptiness checks - Quiz 14medium Collections Fundamentals - Mutable vs immutable interfaces - Quiz 1easy Control Flow as Expressions - When as expression returning value - Quiz 15hard Data Types - Number literal formats (underscore, hex, binary) - Quiz 14medium Functions - Single-expression functions - Quiz 6medium Functions - Named arguments for clarity - Quiz 1easy Kotlin Basics and JVM Runtime - What is Kotlin - Quiz 15hard Loops and Ranges - Repeat function for simple repetition - Quiz 3easy Loops and Ranges - While and do-while loops - Quiz 8hard Operators and Expressions - Operator precedence - Quiz 4medium