title: How can I check if a string has a substring from a List?
body: <p>I am looking for the best way to check if a string contains a substring from a list of keywords.</p>
  
  <p>For example, I create a list like this:</p>
  
  <pre><code>List&lt;String&gt; keywords = new ArrayList&lt;&gt;();
  keywords.add("mary");
  keywords.add("lamb");
  
  String s1 = "mary is a good girl";
  String s2 = "she likes travelling";
  </code></pre>
  
  <p>String s1 has "mary" from the keywords, but string s2 does not have it. So, I would like to define a method:</p>
  
  <pre><code>boolean containsAKeyword(String str, List&lt;String&gt; keywords)
  </code></pre>
  
  <p>Where <code>containsAKeyword(s1, keywords)</code> would return true but <code>containsAKeyword(s2, keywords)</code> would return false. I can return true even if there is a single substring match.</p>
  
  <p>I know I can just iterate over the keywords list and call str.contains() on each item in the list, but I was wondering if there is a better way to iterate over the complete list (avoid O(n) complexity) or if Java provides any built-in methods for this.</p>