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.


Which collection class allows duplicate elements?

  1. Set

  2. List

  3. Queue

  4. Map

The correct answer is: List

A Set does not allow duplicate elements since it adheres to the "unique keys" concept. C: Queue does not allow duplicate elements since it follows a FIFO (First-In-First-Out) structure. D: Map can have duplicate values, but not duplicate keys. B: List is the correct answer because it allows for duplicate elements. This is because list data structures do not have any restrictions on the number of times an element can appear. Therefore, you can have duplicate elements in a list.