• 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

Dan's mock exam: collection classes

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Question 10
a. Each element must be unique.
b. Duplicate elements must not replace old elements.
c. Elements are not key/value pairs.
d. Accessing an element is almost as fast as performing the same operation on an array.
Which of these classes provides the specified features?
a. LinkedList
b. TreeMap
c. TreeSet
d. HashMap
e. HashSet
f. LinkedHashMap
g. LinkedHashSet
h. Hashtable
i. None of the above
answer: (e) HashSet


i wonder why (g) LinkedHashSet isn't correct answer...
according to TIJ 3rd ed., "traversal is cheaper with LinkedHashSet (than HashSet) because of the linked list", so LinkedHashSet fulfills all 4 requirements, or not?
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The API mentions what you said, but adding that a LinkedHashSet is a bit slower than HashSet. Try asking Dan himself.
[ January 24, 2003: Message edited by: Jose Botella ]
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Though I couldn't give the question numbers when answering Dan's Mocks on collections, I realized that there are questions where more than one answer satisfiesd the question, the answer given by Dan is always SuperClass. Just like in this case.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There was a question on one of the Sun mock exams I purchased where (to my mind) two of the answers fulfiled all the requirements.
I'm guessing that if you get such a question in the real exam then you should answer with the collection class that minimally meets the requirements.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The LinkedHashSet must maintain a linked list through each element so the added functionality of the LinkedHashSet does added some time to the put and remove operations.
Having said the above I agree that the term, "Accessing", used in the question is a little vague and could include the "get" operation which does not require additional time relative to the HashSet.get method. For that reason, I think that I will update the question.
I think that rewording the question to remove the ambiquities of the term "accessing" would be less effective than just removing the LinkedHashSet from the answer options.
Thank you for the feedback.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic