title: What is more efficient? An If Else or a HashMap?
body: <p>I'm writing some code in Java to check in which quadrant a coordinate is and I was wondering which method is more efficient to check this: a if-else block or the use of a HashMap.</p>
  
  <p>A HashMap would look like this:</p>
  
  <pre><code>private static final Map&lt;Coordinate,Quadrant&gt; quadMap = new HashMap&lt;Coordinate, Quadrant&gt;(){{
      put(new Coordinate(0,0), Quadrant.Q1);
      put(new Coordinate(0, 1), Quadrant.Q2);
      put(new Coordinate(1, 0), Quadrant.Q3);
      put(new Coordinate(1, 1), Quadrant.Q4);
  }};
  </code></pre>
  
  <p>And then where I want to get my quadrant:</p>
  
  <pre><code>return quadMap.get(coordinate)
  </code></pre>
  
  <p>The if-else implementation:</p>
  
  <pre><code>if (x &lt; 1){
          if (y &lt; 1){
              return Quadrant.Q1;
          } else {
              return Quadrant.Q2;
          }
      } else {
          if (y &lt; 1){
              return Quadrant.Q3;
          } else {
              return Quadrant.Q4;
          }
      }
  </code></pre>
  
  <p>Or is there another, more efficient way to do this?</p>