Java Programming - Objects and Collections - Discussion

Discussion Forum : Objects and Collections - Pointing out the correct statements (Q.No. 2)
2.
Which statement is true for the class java.util.HashSet?
The elements in the collection are ordered.
The collection is guaranteed to be immutable.
The elements in the collection are guaranteed to be unique.
The elements in the collection are accessed using a unique key.
Answer: Option
Explanation:

Option C is correct. HashSet implements the Set interface and the Set interface specifies collection that contains no duplicate elements.

Option A is wrong. 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.

Option B is wrong. The set can be modified.

Option D is wrong. This is a Set and not a Map.

Discussion:
1 comments Page 1 of 1.

Aas said:   1 decade ago
Can you show this problem in program?

Post your comments here:

Your comments will be displayed after verification.