Skip to content
Sharp

Collections · interview question

Why does calling list.clear() on an ArrayList matter in practice?

Multiple choiceMediumchapter-4-curatedpremiumcollectionslist-interface-and-arraylist
Choose one answer
Answer and explanation

Correct answer

D. It removes all elements and resets the size to zero.

Why

The clear method removes all elements from the list, reducing its size to zero, but it does not affect the capacity of the list.

Test yourself on Collections

A free test with instant, explained results. No account needed.

Start free test
All Collections questions →