This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Duplicates in collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Duplicates in collections" Watch "Duplicates in collections" New topic
Author

Duplicates in collections

Sarma Lolla
Ranch Hand

Joined: Oct 21, 2002
Posts: 203
Please select collection(s) that do not reject duplicates ()
A. java.util.List
B. java.util.Set
C. java.util.Map
D. All of the above
I know that Set rejects duplicates in the sense it just ignores if we add again the same element.
Map doesn't reject but updates the values for the same key value.
List happyly accepts any number of duplicates.
So I answered the above question with B. But the Mock says both B and C are correct.
Can any one explain?
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
The question is not well worded.
Given that no duplicate keys will be contained in a Map, the aswer is including Map.
Because "rejecting duplicates" could be thought as producing an error, or the Map not containing the seconddly added object, misinterpretations are possible.


SCJP2. Please Indent your code using UBB Code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Duplicates in collections
 
Similar Threads
generics - why does this work?
Collection question
why will this block of code never work correctly:
ArrayList
Howto generate unique random id