Skip to content
Sharp

Collections · interview question

What does the size() method of a HashMap return?

Multiple choiceEasychapter-4-curatedpremiumcollectionsmap-interface-and-hashmap
Choose one answer
Answer and explanation

Correct answer

D. The number of key-value pairs in the map.

Why

The size() method returns the number of key-value pairs in the map, which is a direct measure of its current occupancy.

Test yourself on Collections

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

Start free test
All Collections questions →