• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

ExamlLab Collections' Set  RSS feed

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??
 
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Saibabaa Pragada
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Map & Hashtable also doesn't allow duplicate elements know ??
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if searching is not a priority, Why we should think of using Set ? I am not clear on the logic behind that
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!