Getting Keys from a LinkedHashMap

N

newsnet customer

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
 
P

Patricia Shanahan

newsnet said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top