Recall & Review
beginner
What Kotlin function checks if a collection has no elements?
The
isEmpty() function returns true if the collection contains no elements.Click to reveal answer
beginner
How do you check if a Kotlin collection has at least one element?
Use the
isNotEmpty() function, which returns true if the collection contains one or more elements.Click to reveal answer
beginner
What property gives the number of elements in a Kotlin collection?
The
size property returns the count of elements in the collection.Click to reveal answer
intermediate
Why is it better to use
isEmpty() instead of size == 0 in Kotlin?Using
isEmpty() is clearer and can be more efficient because it may avoid counting all elements if the collection supports fast emptiness checks.Click to reveal answer
beginner
What will
listOf(1, 2, 3).isNotEmpty() return?It returns
true because the list contains three elements.Click to reveal answer
Which Kotlin function checks if a collection is empty?
✗ Incorrect
The
isEmpty() function returns true if the collection has no elements.What does
collection.size return in Kotlin?✗ Incorrect
size gives the count of elements in the collection.Which function returns true if a Kotlin collection has one or more elements?
✗ Incorrect
isNotEmpty() returns true if the collection is not empty.Why might
isEmpty() be preferred over size == 0?✗ Incorrect
isEmpty() can be more efficient and expresses intent clearly.What is the result of
emptyList<Int>().isNotEmpty()?✗ Incorrect
An empty list returns false for
isNotEmpty().Explain how to check if a Kotlin collection is empty or not.
Think about functions that return true or false based on collection content.
You got /4 concepts.
Describe why using isEmpty() might be better than checking size == 0 in Kotlin collections.
Consider both code clarity and how the collection might be implemented.
You got /3 concepts.