Which statement is true for the Class java.util.HashSet?

Options
- The collection is guaranteed to be immutable.
- The elements in the collection are unique.
- The elements in the collection are ordered.
- The elements in the collection are synchronized.


CORRECT ANSWER : The elements in the collection are unique.

Discussion Board
The elements in the collection are unique.

The above answer is correct. HashSet implements the Set interface and the Set interface specifies collection that contains no duplicate elements. HashSet makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. This a Set and not a Map. The set cannot be modified.

Prajakta Pandit 03-15-2017 11:53 PM

answer is also fault.

The elements are unique in a set when you add them to the set.
BUT when you add 2 different objects to the set and then alter object 1 to the same state as object 2 (example Object Person who has 2 Strings firstName and lastName and equals en hashcode are set on those 2 Strings)

This is possible and you have a double in your set!!!.

Filip 03-8-2017 08:41 AM

Write your comments


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement