Getting Keys from a LinkedHashMap

Discussion in 'Java' started by newsnet customer, Apr 14, 2006.

  1. Hi,

    Consider:

    Key Value
    0001_A car
    0002_B bike
    0003_C bus
    ....

    I want to get the key that maps car. All i know is that "_A" is part of the key.
    Is it possible to get a key from a LinkedHashMap when you only know part of the key?


    Cheers
    ST
     
    newsnet customer, Apr 14, 2006
    #1
    1. Advertising

  2. newsnet customer wrote:
    > Hi,
    >
    > Consider:
    >
    > Key Value
    > 0001_A car
    > 0002_B bike
    > 0003_C bus
    > ...
    >
    > I want to get the key that maps car. All i know is that "_A" is part of the key.
    > Is it possible to get a key from a LinkedHashMap when you only know part of the key?
    >
    >
    > Cheers
    > ST
    >


    You can get anything from any Map, slowly, by iterating through the
    entrySet result checking your criteria.

    If you will only have one key with value "car" and need to do this
    lookup frequently, consider using a pair of maps. The second map would
    have the vehicle names as keys, and the codes as values.

    You cannot benefit from the hash lookup without using a key that has the
    right hash code and compares equal to the key in the Map.

    Patricia
     
    Patricia Shanahan, Apr 14, 2006
    #2
    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. Andrej Litowka

    Can't read a value in a LinkedHashMap

    Andrej Litowka, Nov 20, 2003, in forum: Java
    Replies:
    1
    Views:
    2,732
    John C. Bollinger
    Nov 20, 2003
  2. Markus Innerebner
    Replies:
    1
    Views:
    595
    Markus Innerebner
    May 29, 2004
  3. Markus Innerebner

    direkt Access in a LinkedHashMap

    Markus Innerebner, Jun 28, 2004, in forum: Java
    Replies:
    3
    Views:
    573
    Michael Borgwardt
    Jun 28, 2004
  4. enrique
    Replies:
    8
    Views:
    567
    Kevin McMurtrie
    Apr 29, 2005
  5. Albert

    LinkedHashMap next method ?

    Albert, May 18, 2009, in forum: Java
    Replies:
    4
    Views:
    1,503
    Seamus MacRae
    May 20, 2009
Loading...

Share This Page