Loading

Q1.

Which of the following is true about HashSet?

A. It allows duplicate elements

B. It maintains insertion order

C. It allows one null element

D. It is synchronized by default

Q2.

Which data structure does HashSet use internally?

A. Array

B. Linked List

C. HashMap

D. TreeMap

Q3.

What is the time complexity of add() and contains() in HashSet (average case)?

A. O(1)

B. O(n)

C. O(log n)

D. O(n²)

Q4.

What happens if you add a duplicate element in HashSet?

A. It throws an exception

B. It overwrites the old element

C. It ignores the duplicate

D. It adds duplicate at the end

Q5.

Which of the following is not true about HashSet?

A. HashSet allows duplicate elements

B. HashSet is unordered

C. HashSet allows one null value

D. HashSet uses hashing