Duplicate Keys in a Map !

L

L Clarke

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
 
V

Vova Reznik

L said:
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

It is Map of Maps

key="key1", value - another map where keys are "one", "1", "uno",
"один", "ieden", ...
 
A

Andrew McDonagh

L said:
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
sure... have a map of arrayList objects
 
S

Scott.R.Lemke

L said:
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.
 
T

tom fredriksen

L 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?

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
 
R

Roedy Green

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top