Objects and Collections

Q1: Which statement is true for the class java.util.HashSet?

A The elements in the collection are ordered.

B The collection is guaranteed to be immutable.

C The elements in the collection are guaranteed to be unique.

D The elements in the collection are accessed using a unique key.

ANS:C - The elements in the collection are guaranteed to be unique.

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.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.