aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ExamlLab Collections' Set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "ExamlLab Collections Watch "ExamlLab Collections New topic
Author

ExamlLab Collections' Set

Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
Which is suitable for storing elements that must not appear in the store more than once, if searching is not a priority

A. Set
B. Map
C. Hashtable

Answer is : A..Why ??
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Set- Doesnt allow repetition of values- No duplicates allowed and the elements are not ordered. If you had a similar requirement with ordering- you could choose TreeSet.

Map can contain duplicate keys, so does Hashtable

Update: The above statement is wrong.


Mohamed Sanaulla | My Blog
Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
Map & Hashtable also doesn't allow duplicate elements know ??
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Saibabaa Pragada wrote:Map & Hashtable also doesn't allow duplicate elements know ??


From the API: A map cannot contain duplicate keys; each key can map to at most one value. And Hashtable IS-A Map
Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
Hi Mohammed, A map cannot contain duplicate keys. Set cannot contain duplicate elements. So, I am thinking all the options should be correct. Did I miss any part that you are saying?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Saibabaa Pragada wrote:Hi Mohammed, A map cannot contain duplicate keys. Set cannot contain duplicate elements. So, I am thinking all the options should be correct. Did I miss any part that you are saying?


Ah Am really sorry- Misread the question and details . Its given that: if searching is not a priority - So we can think of using Set. So the second details given is important to note.
Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
if searching is not a priority, Why we should think of using Set ? I am not clear on the logic behind that
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Saibabaa Pragada wrote:if searching is not a priority, Why we should think of using Set ? I am not clear on the logic behind that


Maps help in searching by using the keys. For Set- You would have to iterate through the set.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ExamlLab Collections' Set