Java MCQ: What is a HashSet in Java?
a) A collection that does not allow duplicates and is unordered
b) A collection that maintains insertion order
c) A collection that maps keys to values
d) A collection that allows duplicates
Answer:
a) A collection that does not allow duplicates and is unordered
Explanation:
A HashSet
in Java is a collection that does not allow duplicate elements and does not maintain any particular order of its elements. It is implemented using a hash table.
Understanding HashSet
is crucial for managing collections where uniqueness of elements is required without regard to order.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html