You need to create a class that will store unique object elements. You do not need to sort these elements but they must be unique. What interface might be most suitable to meet this need?

  1. Set

  2. List

  3. Map

  4. Vector


Correct Option: A

AI Explanation

To answer this question, you need to understand the characteristics and purposes of different Java interfaces.

Option A) Set - This option is correct because a Set is a collection that stores unique elements. It does not allow duplicate elements and ensures that all elements are unique. Therefore, a Set interface would be the most suitable for storing unique object elements.

Option B) List - This option is incorrect because a List is a collection that allows duplicate elements and maintains the order of insertion. It does not guarantee uniqueness of elements, which is a requirement in this case.

Option C) Map - This option is incorrect because a Map is a collection that stores key-value pairs. It does not ensure uniqueness of elements, as duplicate values can exist for different keys.

Option D) Vector - This option is incorrect because a Vector is a resizable array that allows duplicate elements. It does not guarantee uniqueness of elements.

The correct answer is A) Set. This option is correct because a Set interface is designed specifically to store unique elements.

Find more quizzes: