Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dan's Collection: Duplicate elements must not replace old elements

 
Cathy Song
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Question 4
� 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

What does this statement mean?
Duplicate elements must not replace old elements
Thanks.
 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cathy, here's an excerpt from HashSet API:

add
public boolean add(Object o)Adds the specified element to this set if it is not already present.
Specified by:
add in interface Set
Overrides:
add in class AbstractCollection
Parameters:
o - element to be added to this set.
Returns:
true if the set did not already contain the specified element.


This mechanism doesn't replace the elements if duplicates are detected.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic