Hash table

Discussion in 'Java' started by ruds, May 25, 2007.

  1. ruds

    ruds Guest

    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??
     
    ruds, May 25, 2007
    #1
    1. Advertising

  2. ruds

    Shane Guest

    ruds wrote:

    > 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??


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

    --
    Math problems? Call 1-800-[(10x)(13i)2]-[sin(xy)/2.362x].
     
    Shane, May 25, 2007
    #2
    1. Advertising

  3. ruds wrote:
    > 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?
     
    Thomas Schodt, May 25, 2007
    #3
  4. "ruds" <> wrote in message
    news:...
    > 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??


    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.
     
    Mike Schilling, May 25, 2007
    #4
  5. ruds

    Roedy Green Guest

    Roedy Green, May 25, 2007
    #5
  6. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Roedy Green schreef:
    > On 24 May 2007 23:00:50 -0700, ruds <> wrote, quoted
    > or indirectly quoted someone who said :
    >
    >> 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??


    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
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.5 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQFGVunSe+7xMGD3itQRAofTAJ9k+bSAVoSuTzhgZbAiT/O4xLLXMwCfXIwf
    L7Am7T8hTVcQnjU4gV/zKgo=
    =qxGz
    -----END PGP SIGNATURE-----
     
    Hendrik Maryns, May 25, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Williams
    Replies:
    2
    Views:
    1,156
    Jacob Yang [MSFT]
    Aug 12, 2003
  2. Rio
    Replies:
    4
    Views:
    1,228
  3. Pieter Claassen
    Replies:
    1
    Views:
    1,137
    CBFalconer
    Aug 4, 2004
  4. rp
    Replies:
    1
    Views:
    562
    red floyd
    Nov 10, 2011
  5. Srijayanth Sridhar
    Replies:
    19
    Views:
    656
    David A. Black
    Jul 2, 2008
Loading...

Share This Page