Java – Looking a data structure that is a Map but in which keys can be values, values can be keys

algorithmdata-structuresjavamap

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.

Best Solution

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