Jwalin Shah
Jwalin Shah

Reputation: 2521

retrieve key by providing value as a input in hashtable

I have input as a values. I need to retrieve key of that values in hashtable.

Please help to me sort out this. Appreciate your help.

Upvotes: 0

Views: 113

Answers (2)

Jon Skeet
Jon Skeet

Reputation: 1502166

Basically that's not how a hash table works - you're expected to look up by key. You can iterate over all the entries and find the - potentially multiple - keys which map to the particular value, but it won't be fast.

Instead, you should consider using a bidirectional map (bimap) such as the ones provided by Guava, assuming your situation really calls for a single-key-to-single-value solution. (There are lots of options around collections in Guava; if you give us more information about your situation, we may be able to help more.)

Upvotes: 3

Aravind Yarram
Aravind Yarram

Reputation: 80194

What you are looking for is a BiMap data structure. Google's guava provides an implementation of it. BidiMap interface in Commons Collections.

Upvotes: 2

Related Questions