Originally posted by Ritu Kapoor:
I've found a following question in a mock exam. Pls tell me which is the correct answer.
Code:
------------------------------------------
Which of the following classes would provide the most efficient implementation of a First In First Out queue?
a. ArrayList
b. LinkedHashMap
c. LinkedHashSet
d. LinkedList
e. HashMap
f. HashSet
g. Hashtable
h. TreeMap
i. TreeSet
j. Vector
k. None of the above
--------------------------------------------------
Should not it be LinkedHashMap, LinkedHashSet and LinkedList
But the correct answer is LinkedList.
Look at it from Data structure point of view.
LinkedList - Simple inserts, one after the other, no sorting, no overhead.
LinkedHasSet - Before making any inserts, verify if there are any duplicates.
LinkedHashMap - Key-Map scenario, essentially lookup if a key exists and then take corrective action.
So LinkedList is something that has only the intelligence of either adding towards the end of the last node [again cud be diff if using a SLL or a DLL]