title: Java - Filtering List Entries by Regex
body: <p>My code looks like this:</p>
  
  <pre><code>List&lt;String&gt; filterList(List&lt;String&gt; list, String regex) {
    List&lt;String&gt; result = new ArrayList&lt;String&gt;();
    for (String entry : list) {
      if (entry.matches(regex)) {
        result.add(entry);
      }
    }
    return result;
  }
  </code></pre>
  
  <p>It returns a list that contains only those entries that match the <code>regex</code>.
  I was wondering if there was a built in function for this along the lines of:</p>
  
  <pre><code>List&lt;String&gt; filterList(List&lt;String&gt; list, String regex) {
    List&lt;String&gt; result = new ArrayList&lt;String&gt;();
    result.addAll(list, regex);
    return result;
  }
  </code></pre>