title: Why switch is faster than if
body: <p>Lots of Java books describe the <code>switch</code> statement as being faster than the <code>if else</code> statement. But I did not find out anywhere <strong>why switch is faster than if</strong>.</p>
  
  <h2>Example</h2>
  
  <p>I have a situation I have to choose any one item out of two. I can use either use</p>
  
  <pre><code>switch (item) {
      case BREAD:
          //eat Bread
          break;
      default:
          //leave the restaurant
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>if (item == BREAD) {
      //eat Bread
  } else {
      //leave the restaurant
  }
  </code></pre>
  
  <p>considering item and BREAD is a constant int value.</p>
  
  <p>In the above example which <strong>is faster in action and why?</strong></p>