• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Collection question

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
# Please select collection(s) that do not reject duplicates

1. java.util.List
2. java.util.Set
3. java.util.Map
4. All of the above

i choosed 1 and 3... proper answer was only 1.. i know that Map is not an instance of ?Collection, but it is still considered a collection...

anyone could comment?

thankx and regars
marco
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
set and map donot take duplicates.lists take duplicates
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The keys in the Map are internally Set and can be retrieved in a Set.
Since Set doesn't allow duplicates the key values in Map are also not allowed to contain the duplicates.
But the values in Map can be duplicate.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Maps also fall under the collection category although they dont explicitly implement the Collection interface. So the right answer would be List. By the way Maps do not reject the new duplicate value. The new value will replace the previous one. In Sets the add method will return false when you try to add a new value.
 
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mistroni
List accepts duplicates, Map also accepts duplicates,new value replaces old value.

Map is not a collection but it will become collection by calling methods like Collection values() ,Set keySet()
 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic