Kotlin - Collections FundamentalsHow can you create a new array by doubling each element of an existing IntArray named numbers in Kotlin?Aval doubled = numbers.forEach { it * 2 }Bval doubled = numbers.map { it * 2 }Cval doubled = numbers.map { it * 2 }.toIntArray()Dval doubled = numbers * 2Check Answer
Step-by-Step SolutionSolution:Step 1: Use map to transform each elementmap applies a function to each element and returns a List.Step 2: Convert List back to IntArraytoIntArray() converts the List to IntArray.Final Answer:val doubled = numbers.map { it * 2 }.toIntArray() -> Option CQuick Check:Use map + toIntArray() to transform IntArray [OK]Quick Trick: Use map and toIntArray() to transform IntArray [OK]Common Mistakes:MISTAKESUsing forEach which returns UnitTrying to multiply array directlyNot converting List back to IntArray
Master "Collections Fundamentals" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Collections Fundamentals - Map creation (mapOf, mutableMapOf) - Quiz 1easy Collections Fundamentals - Iterating collections with forEach - Quiz 4medium Functions - Why functions are first-class in Kotlin - Quiz 13medium Functions - Infix functions for readable calls - Quiz 3easy Kotlin Basics and JVM Runtime - What is Kotlin - Quiz 4medium Kotlin Basics and JVM Runtime - Print and println output - Quiz 5medium Null Safety - Non-nullable types by default - Quiz 1easy Null Safety - Nullable types with ? suffix - Quiz 11easy Operators and Expressions - Operator overloading concept - Quiz 5medium Operators and Expressions - Logical operators (&&, ||, !) - Quiz 3easy