• 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

Duplicate Keys

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are duplicate keys in the following statement? Is it the name of the class?
"An interface that ensures that implementing classes cannot contain duplicate keys."
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it's refering to a Map interface. The keys are used to identify an object in a collection. Example impllementations are hashTable and Hashmap. They store key/value pairs, and the keys can not be duplicate.

Bosun
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If one wants to create a duplicate key with different values then, what class/interface is the best to use, Any Ideas?
Thanks
Nilesh
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would use Map.
Yes, seriously. If you have a duplicate key with a different value, how would you know which value to return for that key? You can't know. All you can do is return all the values for that key, which corresponds to a Map that maps the key to a Collection of values. The key => Collection map is once again unique.
- Peter
 
reply
    Bookmark Topic Watch Topic
  • New Topic