title: Bi-directional Map in Java?
body: <p>I have a simple integer-to-string mapping in Java, but I need to be able to easily retrieve string from integer, and also integer from string. I've tried Map, but it can retrieve only string from integer, it's one way:</p>
  
  <pre><code>private static final Map&lt;Integer, String&gt; myMap = new HashMap&lt;Integer, String&gt;();
  // This works one way:
  String myString = myMap.get(myInteger);
  
  // I would need something like:
  Integer myInteger = myMap.getKey(myString);
  </code></pre>
  
  <p>Is there a right way to do it to have it both directions? </p>
  
  <p>Another problem is that I only have a few constant values that don't change (<code>1-&gt;"low", 2-&gt;"mid", 3-&gt;"high"</code>, so it wouldn't be worth to go for a complicated solution. </p>