title: Finding if a string contains any string in a collection
body: <p>I'm trying to improve the performance of a Java-function I have that is determining whether a given search string contains >0 of the strings in a collection. This could look like premature optimization but the function is called A LOT so any speed up would be very beneficial. </p>
  
  <p>The code currently looks like this:</p>
  
  <pre><code>public static boolean containsAny(String searchString, List&lt;String&gt; searchCollection) {
      int size = searchCollection.size();
      for (int i = 0; i &lt; size; i++) {
          String stringInCollection = searchCollection.get(i);
          if (!Util.isNullOrEmpty(stringInCollection)) {
              // This is a performance optimization of contains.
              if (searchString.indexOf(stringInCollection, 0) &gt; -1) {
                  return true;
              }
          }
      }
      return false;
  }
  </code></pre>
  
  <p>The list typically has about 30 elements and the same collection is reused a lot between each call.</p>
  
  <p>The code above is a pretty straightforward linear search. I don't think it can be significantly improved unless we change the data structure to make it better than O(n). Are there any data structures that would enable me to do that?</p>