File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Duplicate Keys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Duplicate Keys" Watch "Duplicate Keys" New topic

Duplicate Keys

Willie Toma
Ranch Hand

Joined: May 11, 2001
Posts: 78
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."
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
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.


So much trouble in the world -- Bob Marley
Ranch Hand

Joined: Nov 21, 2000
Posts: 71
If one wants to create a duplicate key with different values then, what class/interface is the best to use, Any Ideas?
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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
I agree. Here's the link:
subject: Duplicate Keys
It's not a secret anymore!