title: Java String comparision process
body: <p>I have a concern regarding, how java compare the String and how optimized it is.</p>
  
  <p>Let's consider I require to compare user provided String, with 10 Strings in my code. Out of those 10 Strings 5 are starting with 'A' and other 5 are starting with 'B'.</p>
  
  <p>Now if I write <code>if..elseif..</code> or <code>switch</code>, then each string will be compared until it matches with any String, and under worst case scenario, where either String is getting matched in 9th or 10th condition or not at all. So average 8 to 10 conditions are executing for each input.</p>
  
  <p>Now my question is can we optimize this situation by putting one more condition (kind of filter) before checking the input string with actual value. Like below,</p>
  
  <pre><code>   if(inputString.charAt(0) == 'A'){
              if(){
                  ....
              }else if(){
                  ....
              }
          }else if(inputString.charAt(0) == 'B'){
              if(){
                  ...
              }else if(){
                  ...
              }
          }
  </code></pre>
  
  <p>Can it improve the performance of the system or Java is already internally optimized for this kind of situation. </p>