This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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


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
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Duplicate Keys
 
jQuery in Action, 3rd edition