Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - Duplicate Keys in a Map !

 
Thread Tools Search this Thread
Old 02-22-2006, 08:30 PM   #1
Default Duplicate Keys in a Map !


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



--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access


L Clarke
  Reply With Quote
Old 02-22-2006, 08:36 PM   #2
Vova Reznik
 
Posts: n/a
Default Re: Duplicate Keys in a Map !
L Clarke wrote:
> 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
>
>
>
> --
> Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
> ------->>>>>>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", ...


Vova Reznik
  Reply With Quote
Old 02-22-2006, 08:37 PM   #3
Andrew McDonagh
 
Posts: n/a
Default Re: Duplicate Keys in a Map !
L Clarke wrote:
> 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
>
>
>
> --
> Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
> ------->>>>>>http://www.NewsDemon.com<<<<<<------
> Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

sure... have a map of arrayList objects


Andrew McDonagh
  Reply With Quote
Old 02-22-2006, 08:39 PM   #4
Scott.R.Lemke@gmail.com
 
Posts: n/a
Default Re: Duplicate Keys in a Map !

L Clarke wrote:
> 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



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.



Scott.R.Lemke@gmail.com
  Reply With Quote
Old 02-22-2006, 08:46 PM   #5
Jeffrey Schwab
 
Posts: n/a
Default Re: Duplicate Keys in a Map !
L Clarke wrote:

> 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/tutor...faces/map.html

Scroll down to the section on Multimaps.


Jeffrey Schwab
  Reply With Quote
Old 02-22-2006, 10:10 PM   #6
tom fredriksen
 
Posts: n/a
Default Re: Duplicate Keys in a Map !
L Clarke wrote:
> 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.


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

/tom


tom fredriksen
  Reply With Quote
Old 02-24-2006, 01:27 PM   #7
Roedy Green
 
Posts: n/a
Default Re: Duplicate Keys in a Map !
On Wed, 22 Feb 2006 20:30:20 -0000, "L Clarke" <>
wrote, quoted or indirectly quoted someone who said :

>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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.


Roedy Green
  Reply With Quote
Old 02-27-2006, 11:21 AM   #8
bugbear
 
Posts: n/a
Default Re: Duplicate Keys in a Map !
Jeffrey Schwab wrote:
> L Clarke wrote:
>
>> 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/tutor...faces/map.html
>
> Scroll down to the section on Multimaps.


They mention it,
jakarta common collections DOES it:

http://jakarta.apache.org/commons/co.../MultiMap.html

BugBear


bugbear
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Change keys of keyboard as what you like. geraldmapa Software 0 06-30-2009 09:02 AM
DVD Verdict reviews: THE DIARY OF ALICIA KEYS, A NEW KIND OF LOVE, and more! DVD Verdict DVD Video 0 02-15-2005 10:20 AM
duplicate files -D- A+ Certification 0 02-22-2004 01:02 AM
Here's a list of Keyboard Shortcuts and Hot keys Sean Cleary A+ Certification 0 08-04-2003 03:51 AM
Dos Keys, Window Keys, is there a list of what I must memorize Sean Cleary A+ Certification 0 08-04-2003 03:03 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46