title: Java Search an array for a matching string
body: <p>how can I optimize the following:</p>
  
  <pre><code>final String[] longStringArray = {"1","2","3".....,"9999999"};
  String searchingFor = "9999998"
  for(String s : longStringArray)
      {
          if(searchingFor.equals(s))
          {
              //After 9999998 iterations finally found it
              // Do the rest of stuff here (not relevant to the string/array)
          }
      }
  </code></pre>
  
  <p><strong>NOTE</strong>: The longStringArray is only searched once per runtime &amp; is not sorted &amp; is different every other time I run the program.</p>
  
  <p>Im sure there is a way to improve the worst case performance here, but I cant seem to find it...</p>
  
  <p>P.S. Also would appreciate a solution, where string searchingFor does not exist in the array longStringArray.</p>
  
  <p>Thank you. </p>