Bird
0
0

What is the output of this Kotlin code?

medium📝 query result Q4 of 15
Kotlin - Collections Fundamentals
What is the output of this Kotlin code?
val list = listOf("a", "b", "c")
println(list.isNotEmpty())
println(list.size)
Atrue 3
Bfalse 3
Ctrue 0
Dfalse 0
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate isNotEmpty()

    List has 3 elements, so isNotEmpty() returns true.
  2. Step 2: Evaluate size property

    List size is 3, so list.size returns 3.
  3. Final Answer:

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

    Non-empty list returns true and size 3 [OK]
Quick Trick: isNotEmpty() true if size > 0, size returns element count [OK]
Common Mistakes:
MISTAKES
  • Assuming isNotEmpty() returns false
  • Confusing size with length
  • Expecting size 0 for non-empty list

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes