Kotlin - Collections FundamentalsHow can you combine destructuring with a filter to create a list of values from a map where keys start with 'A'?Amap.filterKeys { it.startsWith("A") }.values.toList()Bmap.map { (k, v) -> if (k.startsWith("A")) v else null }Cmap.filter { (k, _) -> k.startsWith("A") }.map { (_, v) -> v }Dmap.filterValues { it.startsWith("A") }.keys.toList()Check Answer
Step-by-Step SolutionSolution:Step 1: Use filter with destructuring to check keysFilter entries where key starts with 'A' using (k, _) destructuring.Step 2: Map filtered entries to valuesExtract values from filtered entries using (_, v) destructuring.Final Answer:map.filter { (k, _) -> k.startsWith("A") }.map { (_, v) -> v } -> Option CQuick Check:Filter keys with destructuring, then map values [OK]Quick Trick: Filter with (k, _) then map with (_, v) [OK]Common Mistakes:MISTAKESFiltering values instead of keysUsing map with if-else returning nullsConfusing keys and values in filter/map
Master "Collections Fundamentals" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Control Flow as Expressions - Why expressions over statements matters - Quiz 2easy Functions - Why functions are first-class in Kotlin - Quiz 15hard Functions - Infix functions for readable calls - Quiz 7medium Functions - Parameters with default values - Quiz 14medium Kotlin Basics and JVM Runtime - How Kotlin compiles to JVM bytecode - Quiz 5medium Kotlin Basics and JVM Runtime - Main function as entry point - Quiz 1easy Operators and Expressions - Range operator (..) and in operator - Quiz 3easy Operators and Expressions - Operator precedence - Quiz 5medium Variables and Type System - Constant values with const val - Quiz 6medium Variables and Type System - Var for mutable references - Quiz 1easy