Re: How can i implements a class like an HashMap but with 2 keys ?
- From: Roedy Green <see_website@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 28 Aug 2007 22:38:57 GMT
On Tue, 28 Aug 2007 14:02:21 +0200, Rob <nomail@nomail> wrote, quoted
or indirectly quoted someone who said :
i am a newbie, i want to create a class that works like an HashMap but
with 2 keys, get(key1,key2) -> value
Here are three solutions:
1. use two HashMaps on the same set of objects. Then you can look up
by either key.
2. create a Pair class that contains key1 and key2 with an ^ (xor)
combined hashCode. Then Pair is a single key for both building and
lookup. You need both keys to lookup, like a safety deposit box.
3. concatenate your two String keys into one.
See http://mindprod.com/jgloss/hashcode.html
http://mindprod.com/jgloss/hashmap.html
http://mindprod.com/jgloss/hashtable.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
.
- Follow-Ups:
- Re: How can i implements a class like an HashMap but with 2 keys ?
- From: Patricia Shanahan
- Re: How can i implements a class like an HashMap but with 2 keys ?
- References:
- Prev by Date: Re: Retrieving mac address of remote computer
- Next by Date: Re: Adding SCROLLBARS to a JTextArea
- Previous by thread: Re: How can i implements a class like an HashMap but with 2 keys ?
- Next by thread: Re: How can i implements a class like an HashMap but with 2 keys ?
- Index(es):
Relevant Pages
|