title: How to (dynamically) change Java stream's filter conditions?
body: <p>I have a few classes of the following general form, where <code>this.words</code> is a <code>List&lt;String&gt;</code> containing one word per element:</p>
  
  <pre><code>public ArrayList&lt;String&gt; wordsInclZ() {
      ArrayList&lt;String&gt; results = new ArrayList&lt;&gt;();
  
      this.words.stream()
          .filter(word -&gt; word.contains("z"))
          .forEach(word -&gt; results.add(word));
  
      return results;
  }
  </code></pre>
  
  <p>The only bit I have to change are the filter conditions, i.e., the expression inside <code>.filter()</code>. This doesn't appear to be a terrible copy-paste situation, however I'd like to learn if it was possible to write neater code.</p>
  
  <p>Is there a concise way to generalize this functionality? I guess I'm basically asking can I and how should I pass the lambda to the <code>.filter()</code> as a parameter of a general method that handles the rest of the above method's functionality.</p>