Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Getting Keys from a LinkedHashMap

Reply
Thread Tools

Getting Keys from a LinkedHashMap

 
 
newsnet customer
Guest
Posts: n/a
 
      04-14-2006
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

 
Reply With Quote
 
 
 
 
Patricia Shanahan
Guest
Posts: n/a
 
      04-14-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LinkedHashMap next method ? Albert Java 4 05-20-2009 12:34 AM
LinkedHashMap::put: object destroyed too soon? enrique Java 8 04-29-2005 04:46 AM
direkt Access in a LinkedHashMap Markus Innerebner Java 3 06-28-2004 08:58 AM
Problems while removing an Element from LinkedHashMap Markus Innerebner Java 1 05-29-2004 10:39 AM
Can't read a value in a LinkedHashMap Andrej Litowka Java 1 11-20-2003 06:44 PM



Advertisments