Java MCQ: What is a LinkedHashSet in Java?
a) A set that maintains insertion order
b) A set that does not allow duplicates but is unordered
c) A list that allows duplicates
d) A map that stores key-value pairs
Answer:
a) A set that maintains insertion order
Explanation:
A LinkedHashSet
in Java is a set that maintains the order of elements based on their insertion order. Like HashSet
, it does not allow duplicate elements, but it provides a predictable iteration order.
Understanding LinkedHashSet
is important for managing collections where both uniqueness and insertion order of elements are required.
Reference links:
https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html