Which method of PriorityQueue returns the element without removing it?
Apoll()
Bremove()
Cpeek()
Dpop()
Correct Answer:
C. peek()
EXPLANATION
peek() returns the head element without removing it. poll() removes and returns, remove() throws exception if empty, and pop() is not a PriorityQueue method.
What is the difference between ArrayList and Vector?
AArrayList is synchronized, Vector is not
BVector is synchronized, ArrayList is not
CBoth are synchronized
DNeither is synchronized
Correct Answer:
B. Vector is synchronized, ArrayList is not
EXPLANATION
Vector is a legacy synchronized collection, while ArrayList is unsynchronized but faster. For thread-safety with ArrayList, use Collections.synchronizedList().
Which of the following maintains insertion order in Java?
AHashSet
BTreeSet
CLinkedHashSet
DConcurrentHashMap
Correct Answer:
C. LinkedHashSet
EXPLANATION
LinkedHashSet maintains insertion order using a doubly-linked list. HashSet does not maintain order, TreeSet maintains sorted order, and ConcurrentHashMap doesn't guarantee insertion order.