Bird
0
0

What does destructuring in Kotlin collection iteration allow you to do?

easy📝 Conceptual Q11 of 15
Kotlin - Collections Fundamentals
What does destructuring in Kotlin collection iteration allow you to do?
for ((key, value) in map) { ... }
AOnly access the value in the loop
BOnly access the key in the loop
CAccess both key and value directly in the loop variables
DModify the map while iterating
Step-by-Step Solution
Solution:
  1. Step 1: Understand destructuring syntax

    In Kotlin, for ((key, value) in map) extracts both key and value from each map entry.
  2. Step 2: Recognize loop variable usage

    This lets you use key and value directly inside the loop without extra calls.
  3. Final Answer:

    Access both key and value directly in the loop variables -> Option C
  4. Quick Check:

    Destructuring = direct access to parts [OK]
Quick Trick: Destructuring splits pairs into variables directly [OK]
Common Mistakes:
MISTAKES
  • Thinking only key or value is accessible
  • Trying to modify map inside loop
  • Not using parentheses for destructuring

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes