Kotlin - Data TypesGiven a list of Strings, how can you create a new list where each String is converted to uppercase, respecting String immutability?Alist.replaceAll { it.toUpperCase() }Blist.forEach { it.toUpperCase() }Cval upperList = list.map { it.toUpperCase() }Dlist.map { it.toUpperCase() = it }Check Answer
Step-by-Step SolutionSolution:Step 1: Understand how to transform list elements immutablyUse map to create a new list with transformed elements.Step 2: Check each option for correctnessval upperList = list.map { it.toUpperCase() } correctly uses map to return new uppercase Strings. list.forEach { it.toUpperCase() } calls toUpperCase but ignores result. list.map { it.toUpperCase() = it } has invalid assignment inside lambda. list.replaceAll { it.toUpperCase() } uses non-existent replaceAll on list.Final Answer:val upperList = list.map { it.toUpperCase() } -> Option CQuick Check:Use map to transform list immutably [OK]Quick Trick: Use map to create new list with transformed Strings [OK]Common Mistakes:MISTAKESUsing forEach without capturing resultsTrying to assign inside lambdaUsing non-existent list methods
Master "Data Types" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Collections Fundamentals - Array creation and usage - Quiz 9hard Control Flow as Expressions - Smart casts in when and if - Quiz 4medium Data Types - Boolean type and logical operators - Quiz 9hard Data Types - Int, Long, Float, Double number types - Quiz 13medium Data Types - Int, Long, Float, Double number types - Quiz 3easy Data Types - Boolean type and logical operators - Quiz 13medium Data Types - Char type and Unicode behavior - Quiz 4medium Functions - Local functions (nested functions) - Quiz 2easy Loops and Ranges - While and do-while loops - Quiz 8hard Null Safety - Why null safety is Kotlin's defining feature - Quiz 15hard