Link to home
Start Free TrialLog in
Avatar of rin_r
rin_r

asked on

Dual key

I need some HashMap or any other Collection which I can create and search using a dual key.
Avatar of zzynx
zzynx
Flag of Belgium image

>> using a dual key.
Do you mean e.g. two String's? Or a String and an Integer?
Each Object can be used as a key, so also instances of your own class (that contains e.g. a String and an Integer)
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if you want your data keyed on two seperate keys then use two maps.
if you want to combine them you can really do it however you want as long as you implement equals() and hashcode() according to their contracts in the javadoc
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrigank
mrigank

Your map will look like

PrimaryMap

key : 1    value : secondaryMap
                        key : a     value : object with key 1 and a
                        key : b     value : object with key 1 and b
key : 2    value : secondaryMap
                        key : a     value : object with key 2 and a
key : 3    value : secondaryMap
                        key : c     value : object with key 3 and c
                        key : a     value : object with key 3 and a
Avatar of rin_r

ASKER

Thank You all
thanx 4 axxepting