Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


What type of collection does entrySet() return?

  1. List

  2. Set

  3. Queue

  4. Map

The correct answer is: Set

The entrySet() method returns a Set because it is designed to return all pairs (key-value) contained in a Map as a Set. Even though a Set is similar to a List in that both can store multiple values, a Set is more suitable since it does not allow duplicates. A Queue on the other hand is used for specific data manipulation such as insertion and deletion at different ends, and thus does not relate to the entrySet() method. Finally, although a Map also stores key-value pairs, it does not return the entire entries as a Set and therefore is not the correct type of collection for the entrySet() method.