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 / May 2007

Tip: Looking for answers? Try searching our database.

Hash table

Thread view: 
ruds - 25 May 2007 07:00 GMT
hi,
I want to know how can i retrive a key from the given value from a
hash table?
suppose my table conatins:
KEY     VALUE
1             3
2            10
3            12
4            15
if i have value 10 how do i get its corresponding key??
Shane - 25 May 2007 07:04 GMT
> hi,
> I want to know how can i retrive a key from the given value from a
[quoted text clipped - 6 lines]
> 4            15
> if i have value 10 how do i get its corresponding key??

The same way you knew where to insert the other values into your hash?

Signature

Math problems? Call 1-800-[(10x)(13i)2]-[sin(xy)/2.362x].

Thomas Schodt - 25 May 2007 07:37 GMT
> hi,
> I want to know how can I retrive a key from the given value from a
> hash table?

suppose your table contains:
KEY     VALUE
1            10
2            10
3            20
4            20
if you have value 10 which is its corresponding key?
Mike Schilling - 25 May 2007 08:40 GMT
> hi,
> I want to know how can i retrive a key from the given value from a
[quoted text clipped - 6 lines]
> 4            15
> if i have value 10 how do i get its corresponding key??

You can iterate throught the set of entries (Map.entrySet()), looking for a
match.  Or, if the values are unique, you can create a second hash table
that reverses keys and values, and look it up directly.
Roedy Green - 25 May 2007 09:35 GMT
>hi,
>I want to know how can i retrive a key from the given value from a
[quoted text clipped - 6 lines]
>4            15
>if i have value 10 how do i get its corresponding key??

see http://mindprod.com/jgloss/hashtable.html
http://mindprod.com/jgloss/hashmap.html
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Hendrik Maryns - 25 May 2007 14:51 GMT
Roedy Green schreef:

>> hi,
>> I want to know how can i retrive a key from the given value from a
[quoted text clipped - 6 lines]
>> 4            15
>> if i have value 10 how do i get its corresponding key??

Jakarta Commons Collections defines the BidiMap interface and gives some
implementations.

I can provide you with a generified version if you wish.

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html


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.