Question 11 • Each element must be unique. • Duplicate elements must not replace old elements. • Elements are not key/value pairs. • Accessing an element can be almost as fast as performing a similar 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. Hashtable h. None of the above answer = e But a HashSet implements a Set which cannot contain duplicate values so the second statement "duplicate elements must not replace old elements" is not true for a Hashset because it can't contain duplicate values!!! So how come this is the correct answer ? [ January 07, 2004: Message edited by: Kristof Camelbeke ] [ January 07, 2004: Message edited by: Kristof Camelbeke ]
I think Dan must have meant that when you add a duplicate item then the item that is last added to the collection will not replace the already existing item in the collection. Dan?
Try your free <a href="http://www.javacertificate.com" target="_blank" rel="nofollow">SCJP 1.4</a> certification centre.<br />Try your free <a href="http://www.j2eecertificate.com" target="_blank" rel="nofollow">SCWCD</a> certification centre.<br />Try your free <a href="http://www.ejbcertificate.com" target="_blank" rel="nofollow">SCBCD</a> certification centre.<br />Try your <a href="http://www.webspherecertificate.com" target="_blank" rel="nofollow">Websphere (Test 285) </a> certification centre.<br />Try your <a href="http://www.j2mecertificate.com" target="_blank" rel="nofollow">SCMAD</a> certification centre. (New)<br /> <br /><a href="http://blogs.javacertificate.com" target="_blank" rel="nofollow">Java/J2EE Certification Blogging</a>
i1 and i2 are two equal objects. We can successfully add i1 to the HashSet because the Hashset doesn't contain an object that is equal to i1 (it's empty anyway). But we can't add i2 to the HashSet because it already contains i1. And i1 stays in the HashSet. [ January 07, 2004: Message edited by: Yosi Hendarsjah ] [ January 07, 2004: Message edited by: Yosi Hendarsjah ]
Kristof, Thank you for your question. I can see that I need to come up with something that is a little more clear. On the next version of the exam, I'll replace the old statement with this one. "Contains no duplicate elements."
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.