Bird
0
0

Which Kotlin function checks if a collection has no elements?

easy📝 Conceptual Q11 of 15
Kotlin - Collections Fundamentals
Which Kotlin function checks if a collection has no elements?
A<code>count()</code>
B<code>isNotEmpty()</code>
C<code>size()</code>
D<code>isEmpty()</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of isEmpty()

    This function returns true if the collection has zero elements.
  2. Step 2: Compare with other functions

    isNotEmpty() checks for one or more elements, count() and size return the number of elements but do not return a boolean.
  3. Final Answer:

    isEmpty() -> Option D
  4. Quick Check:

    Check empty collection with isEmpty() = true [OK]
Quick Trick: Use isEmpty() to check for no elements [OK]
Common Mistakes:
MISTAKES
  • Confusing isEmpty() with isNotEmpty()
  • Using count() to check emptiness
  • Calling size() as a function instead of property

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes