"value" to find a "key"

Discussion in 'Java' started by John, Mar 12, 2008.

  1. John

    John Guest

    Is there such a "Map" in java I can easily trace the key by its value,
    assuming the values are also unique ?


    John,
     
    John, Mar 12, 2008
    #1
    1. Advertising

  2. John

    Eric Sosman Guest

    John wrote:
    >
    > 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.

    --
     
    Eric Sosman, Mar 12, 2008
    #2
    1. Advertising

  3. John

    John Guest

    Thanks Eric,
    I think I will try your second suggestion.

    John,



    On Mar 12, 3:29 pm, Eric Sosman <> wrote:
    > John wrote:
    >
    > > 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.
    >
    > --
    >
     
    John, Mar 12, 2008
    #3
  4. John

    Roedy Green Guest

    On Wed, 12 Mar 2008 15:12:47 -0700 (PDT), John <>
    wrote, quoted or indirectly quoted someone who said :

    >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
     
    Roedy Green, Mar 13, 2008
    #4
  5. Thomas Schodt, Mar 13, 2008
    #5
  6. John

    Nic Guest

    On Mar 13, 6:12 am, John <> wrote:
    > 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
     
    Nic, Mar 13, 2008
    #6
  7. John

    Lew Guest

    Nic wrote:
    > On Mar 13, 6:12 am, John <> wrote:
    >> 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


    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.

    --
    Lew
     
    Lew, Mar 13, 2008
    #7
    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. Zenobia
    Replies:
    2
    Views:
    3,981
    Zenobia
    Jun 23, 2004
  2. Ikke
    Replies:
    4
    Views:
    2,031
    Alexander Bartolich
    Aug 19, 2009
  3. M P
    Replies:
    1
    Views:
    502
  4. Une bévue
    Replies:
    5
    Views:
    156
    Une bévue
    Aug 10, 2006
  5. Antonio Quinonez
    Replies:
    2
    Views:
    180
    Antonio Quinonez
    Aug 14, 2003
Loading...

Share This Page