getting key using value

V

vk02720

Is there any way to retrieve the key using the value from
HashMap/Properties ?
containsValue(key) just returns true/false and not the actual key or
entry.
I have pairs of one-to-one mappings that I have to use both ways. What
data structure can be used ?
 
T

Thomas Weidenfeller

vk02720 said:
Is there any way to retrieve the key using the value from
HashMap/Properties ?
containsValue(key) just returns true/false and not the actual key
or
entry.

I guess you mean containsValue(value). And no, there is no such beast
which delivers all keys (note the plural) for a particular value. You
have to iterate over the set of entries and check the values of all the
entries to find the keys.
I have pairs of one-to-one mappings that I have to use both ways. What
data structure can be used ?

For a quick hack two maps. One mapping A -> B and the other on for the
reverse lookup B -> A. Both maps wrapped in a class which has to ensure
consistency (both maps have to be updated at the same time).

/Thomas
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top