Bird
0
0

What will this Kotlin code print?

medium📝 query result Q5 of 15
Kotlin - Collections Fundamentals
What will this Kotlin code print?
val numbers = listOf()
println(numbers.isEmpty())
println(numbers.size)
Atrue 0
Bfalse 0
Ctrue 1
Dfalse 1
Step-by-Step Solution
Solution:
  1. Step 1: Check if list is empty

    numbers is an empty list, so isEmpty() returns true.
  2. Step 2: Check size of list

    Empty list size is 0, so numbers.size returns 0.
  3. Final Answer:

    true\n0 -> Option A
  4. Quick Check:

    Empty list isEmpty() true and size 0 [OK]
Quick Trick: Empty list returns true for isEmpty() and size 0 [OK]
Common Mistakes:
MISTAKES
  • Assuming isEmpty() returns false
  • Expecting size 1 for empty list
  • Confusing isEmpty() with isNotEmpty()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes