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?
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.
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.
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.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop