Is there such a "Map" in java I can easily trace the key by its value,
assuming the values are also unique ?
John,
Eric Sosman - 12 Mar 2008 23:29 GMT
> Is there such a "Map" in java I can easily trace the key by its value,
> assuming the values are also unique ?
Not that I know of. You could always use two Maps, one
for name-to-phone and the other for phone-to-name. If you
happen to know *for certain* that names and numbers are never
alike, you could use a single Map and enter each item twice,
once as name-and-phone and once as phone-and-name.

Signature
Eric.Sosman@sun.com
John - 12 Mar 2008 23:54 GMT
Thanks Eric,
I think I will try your second suggestion.
John,
> > Is there such a "Map" in java I can easily trace the key by its value,
> > assuming the values are also unique ?
[quoted text clipped - 7 lines]
> --
> Eric.Sos...@sun.com
Roedy Green - 13 Mar 2008 06:10 GMT
>Is there such a "Map" in java I can easily trace the key by its value,
>assuming the values are also unique ?
You create a second map where your values act as keys.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Thomas Schodt - 13 Mar 2008 07:39 GMT
> Is there such a "Map" in java I can easily trace the key by its value,
> assuming the values are also unique ?
http://commons.apache.org/collections/apidocs/org/apache/commons/collections/bid
imap/TreeBidiMap.html
Nic - 13 Mar 2008 09:54 GMT
> Is there such a "Map" in java I can easily trace the key by its value,
> assuming the values are also unique ?
>
> John,
The map you imaged does not exist in the JDK..
But if the values are unique, you can use two maps to resolve that
problem.
A--B and B--A
Lew - 13 Mar 2008 14:36 GMT
>> Is there such a "Map" in java I can easily trace the key by its value,
>> assuming the values are also unique ?
[quoted text clipped - 5 lines]
> problem.
> A--B and B--A
You can also have each Map's value be some kind of Pair class that holds the A
and B values in a single object. That way you have both items whichever Map
you used to reach it, and their association is preserved while you're using
them. The different Maps analogize to multiple indexes in a database, all
organizing the same tuples via different lookup keys.

Signature
Lew