Which package contains the HashSet class in Java?
A
java.array B
java.collection C
java.util D
java.set
Analysis & Theory
`HashSet` is part of the `java.util` package.
What is the main feature of a HashSet?
A
Allows duplicate elements B
Maintains insertion order C
Does not allow duplicates D
Sorted automatically
Analysis & Theory
`HashSet` does not allow duplicate elements.
What is the time complexity of basic operations like add, remove, and contains in HashSet?
A
O(n) B
O(log n) C
O(1) D
O(n log n)
Analysis & Theory
`HashSet` provides constant time O(1) performance for basic operations in average case.
Which of the following is true about HashSet element order?
A
Maintains insertion order B
Maintains sorted order C
No guaranteed order D
Reverses order automatically
Analysis & Theory
`HashSet` does not guarantee the order of its elements.
Which interface does HashSet implement?
A
Map B
List C
Set D
Queue
Analysis & Theory
`HashSet` implements the `Set` interface.
How can you create a new HashSet in Java?
A
new HashSet() B
HashSet.create() C
HashSet.add() D
new Set()
Analysis & Theory
You can create a HashSet using: `HashSet<Type> set = new HashSet<>();`
Which method is used to add elements to a HashSet?
A
insert() B
append() C
add() D
put()
Analysis & Theory
Use `add(element)` to add elements to a `HashSet`.
Which method checks if a HashSet contains a specific element?
A
has() B
contains() C
exists() D
check()
Analysis & Theory
`contains(element)` returns true if the element is present in the set.
What happens if you add a duplicate element to a HashSet?
A
It throws an exception B
It overwrites the element C
It is ignored silently D
It creates a copy
Analysis & Theory
Adding a duplicate element does nothing; it is simply ignored.
Which method removes all elements from a HashSet?
A
clear() B
removeAll() C
deleteAll() D
empty()
Analysis & Theory
`clear()` removes all elements from the HashSet.