Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

"value" to find a "key"

Thread view: 
John - 12 Mar 2008 23:12 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.