Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Duplicate Keys in a Map !

Thread view: 
L Clarke - 22 Feb 2006 20:30 GMT
Hi,

I know that having duplicate keys in a map is not possible, but is there
anything in java that can do such a thing?

example;

key1
- "one"
- "1"
- "uno"

key2
- "two"
- "2"
- "ect"

so by using key2 I can access all the data (return an enumeration ect)
associated with key2.

thanks in advance
lee
Vova Reznik - 22 Feb 2006 20:36 GMT
> Hi,
>
[quoted text clipped - 23 lines]
>       ------->>>>>>http://www.NewsDemon.com<<<<<<------
> Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

It is Map of Maps

key="key1", value - another map where keys are "one", "1", "uno",
"один", "ieden", ...
Andrew McDonagh - 22 Feb 2006 20:37 GMT
> Hi,
>
[quoted text clipped - 23 lines]
>       ------->>>>>>http://www.NewsDemon.com<<<<<<------
> Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
 sure... have a map of arrayList objects
Scott.R.Lemke@gmail.com - 22 Feb 2006 20:39 GMT
> Hi,
>
[quoted text clipped - 18 lines]
> thanks in advance
> lee

You could have a map where the value is a datastructure that holds an
indeterminate amount of values. Or you could (ab)use a hashmap in ways
no hashmap should be (ab)used.
Jeffrey Schwab - 22 Feb 2006 20:46 GMT
> I know that having duplicate keys in a map is not possible, but is there
> anything in java that can do such a thing?

http://java.sun.com/docs/books/tutorial/collections/interfaces/map.html

Scroll down to the section on Multimaps.
bugbear - 27 Feb 2006 11:21 GMT
>> I know that having duplicate keys in a map is not possible, but is
>> there anything in java that can do such a thing?
>
> http://java.sun.com/docs/books/tutorial/collections/interfaces/map.html
>
> Scroll down to the section on Multimaps.

They mention it,
jakarta common collections DOES it:

http://jakarta.apache.org/commons/collections/apidocs-COLLECTIONS_3_1/org/apache
/commons/collections/MultiMap.html


  BugBear
tom fredriksen - 22 Feb 2006 22:10 GMT
> I know that having duplicate keys in a map is not possible, but is there
> anything in java that can do such a thing?
[quoted text clipped - 13 lines]
> so by using key2 I can access all the data (return an enumeration ect)
> associated with key2.

Just use an ArrayList as the value in the Hash, then you iterate the AL
when its returned.

/tom
Roedy Green - 24 Feb 2006 13:27 GMT
>I know that having duplicate keys in a map is not possible, but is there
>anything in java that can do such a thing?

sure a HashMap where the value is an array or ArrayList of the
duplicate values.  When you discover the dup, you have to manage it
yourself by adding your element to the array/ArrayList/Collection

HashMap just hands you back the list of duplicates.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.