This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Duplicate Keys" Watch "Duplicate Keys" New topic
Author

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.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
NILESH PATEL
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?
Thanks
Nilesh
Peter den Haan
author
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
 
Consider Paul's rocket mass heater.
 
subject: Duplicate Keys
 
Similar Threads
Read duplicate keys from properties file
duplicates in collection
sorting a array
HashMaps
Duplicate keys in Hashmap returns null get("key")