Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

duplicates in collection

 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q. From following interfaces/class, identify ones that do not allow duplicates?
The answer given is Map and Set. Why Map?
 
Alton Hernandez
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps because Map does not allow duplicate keys.
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
map cares about unique identifiers.
set does not allow duplicates.
 
Alton Hernandez
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the Java API Doc:

A map cannot contain duplicate keys; each key can map to at most one value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic