views:

219

answers:

3

A Map maps from keys to values and provides quick access based on the knowledge of the key.

Does there exist a data structure like Maps which supports both key to value and value to key access? Sometimes I may want to derefence the Map via the value, while other times by the key.

+5  A: 

Not in the JDK, but you can find a good BiMap implementation in the Google Collections : http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/BiMap.html

Guillaume
+5  A: 

Apache Commons Collections provides a BidiMap which serves this purpose.

pugmarx
+2  A: 

Have a look at org.apache.commons.collections.BidiMap.

Defines a map that allows bidirectional lookup between key and values.

pgras