If you feel the pain brings some third-party library. How about this simple class.
public class BiMap<K,V> { HashMap<K,V> map = new HashMap<K, V>(); HashMap<V,K> inversedMap = new HashMap<V, K>(); void put(K k, V v) { map.put(k, v); inversedMap.put(v, k); } V get(K k) { return map.get(k); } K getKey(V v) { return inversedMap.get(v); } }
Make sure that class K and V have the correct hashCode implementation.
Javanator Feb 05 '16 at 8:46 2016-02-05 08:46
source share