Tell me please, there any methods in standard library for implementation some simple dictionary look like: "a=10,b=11,c=12...". I know about HashMap, but as I know we can`t get key by value, just value by key.
Asked
Active
Viewed 135 times
0
-
Could it be "can`t get **key(s)** by value" also? – Bhesh Gurung Apr 16 '14 at 18:19
-
There is no meaning of look up by value because it can be duplicated and can result in multiple keys. – Braj Apr 16 '14 at 18:30
-
i have alphabet. do you see some alphabet with two equals letters? i hope that java have more ways for this problem without entryset – mechanikos Apr 16 '14 at 18:37
-
How many values do you have in your map? Are key and value both unique? – Braj Apr 16 '14 at 18:50
-
ALPHABET! a=10,b=11...z=.... 1 to 1 unique – mechanikos Apr 17 '14 at 15:56
2 Answers
2
if key & value are all identify, and 1 to 1, then you can write a class which have 2 Map,
1 Map store key:value, another store value:key, so that you can do search in both way.
Also, if key & value have fixed relationship which could be convert by a function, then you can use that function to convert key & value to each other.

Eric
- 22,183
- 20
- 145
- 196
1
Take a look at Guava BiMap. Seems what you're looking for.
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/BiMap.html

Andres
- 10,561
- 4
- 45
- 63