Bird
0
0

Which of the following best describes the map created by mapOf in Kotlin?

easy📝 Conceptual Q1 of 15
Kotlin - Collections Fundamentals
Which of the following best describes the map created by mapOf in Kotlin?
AAn immutable map whose entries cannot be changed after creation
BA mutable map that allows adding and removing entries
CA map that automatically sorts keys in ascending order
DA map that only accepts integer keys
Step-by-Step Solution
Solution:
  1. Step 1: Understand mapOf

    mapOf creates a map with fixed entries that cannot be modified.
  2. Step 2: Differentiate from mutableMapOf

    mutableMapOf creates a map that can be changed after creation.
  3. Final Answer:

    An immutable map whose entries cannot be changed after creation -> Option A
  4. Quick Check:

    Immutable map created by mapOf [OK]
Quick Trick: mapOf creates immutable maps only [OK]
Common Mistakes:
MISTAKES
  • Confusing mapOf with mutableMapOf
  • Assuming mapOf creates a sorted map
  • Thinking mapOf restricts key types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes