• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Collections

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ritu Kapoor:
Should not it be LinkedHashMap, LinkedHashSet and LinkedList

But the correct answer is LinkedList.



Try it and see.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic