11
What is the primary difference between a `HashSet` and a `LinkedHashSet` in the Java Collections Framework?
A)
A `HashSet` uses a tree structure to store elements
B)
A `LinkedHashSet` is synchronized, while a `HashSet` is not
C)
A `LinkedHashSet` maintains insertion order, while a `HashSet` does not
D)
A `HashSet` allows duplicate elements, while a `LinkedHashSet` does not
Answer & Solution
Answer: Option
C
12
Which interface in the Java Collections Framework represents a collection of elements with no specific order?
A)
`List`
B)
`Map`
C)
`Collection`
D)
`Set`
Answer & Solution
Answer: Option
D
13
What is the primary difference between a `Queue` and a `Deque` in the Java Collections Framework?
A)
A `Queue` represents a single-ended queue, while a `Deque` represents a double-ended queue
B)
A `Queue` allows duplicate elements, while a `Deque` does not
C)
A `Deque` is synchronized, while a `Queue` is not
D)
A `Queue` is indexed, while a `Deque` is not
Answer & Solution
Answer: Option
A
14
Which class is typically used to implement a `Deque` in the Java Collections Framework?
A)
`LinkedList`
B)
`HashMap`
C)
`HashSet`
D)
`ArrayDeque`
Answer & Solution
Answer: Option
D
15
In the Java Collections Framework, which class allows you to create a synchronized (thread-safe) collection?
A)
`ArrayList`
B)
`HashMap`
C)
`Collections`
D)
`HashSet`
Answer & Solution
Answer: Option
C
16
Which interface in the Java Collections Framework extends the `Set` interface and represents a collection of elements stored in a sorted order?
A)
`Map`
B)
`SortedSet`
C)
`Queue`
D)
None of These
Answer & Solution
Answer: Option
B
17
What is the purpose of the `Comparator` interface in Java Collections Framework?
A)
It represents a generic collection
B)
It provides methods for hashing elements
C)
It defines a comparison function for ordering elements
D)
It represents a synchronized collection
Answer & Solution
Answer: Option
C
18
Which class is typically used to implement a `SortedSet` in the Java Collections Framework?
A)
`HashSet`
B)
`LinkedHashSet`
C)
`ArrayList`
D)
`TreeSet`
Answer & Solution
Answer: Option
D
19
In the Java Collections Framework, which interface represents a last-in, first-out (LIFO) stack of elements?
A)
`Stack`
B)
`Queue`
C)
`List`
D)
`Deque`
Answer & Solution
Answer: Option
A
20
What is the primary difference between a `Stack` and a `Queue` in the Java Collections Framework?
A)
A `Queue` allows duplicate elements, while a `Stack` does not
B)
A `Stack` allows duplicate elements, while a `Queue` does not
C)
A `Queue` uses a LIFO order, while a `Stack` uses a FIFO order
D)
A `Stack` uses a LIFO (Last-In-First-Out) order, while a `Queue` uses a FIFO (First-In-First-Out) order
Answer & Solution
Answer: Option
D