title: How do I filter a stream of integers into a list?
body: <p>I am trying to process a stream of <code>Integers</code> and collect the integers that match a predicate (via the <code>compare()</code> function) into a list. Here's a rough outline of the code I've written.</p>
  
  <pre><code>private List&lt;Integer&gt; process() {
      Z z = f(-1);
      return IntStream.range(0, 10)
          .filter(i -&gt; compare(z, f(i)))
          .collect(Collectors.toCollection(ArrayList::new)); // Error on this line
  }
  
  private boolean compare(Z z1, Z z2) { ... }
  private Z f(int i) { ... }
  </code></pre>
  
  <p>Unfortunately my solution does not compile and I cannot make sense of the compiler error for the line highlighted:</p>
  
  <blockquote>
    <p>The method collect(Supplier&lt;R>, ObjIntConsumer&lt;R>, BiConsumer&lt;R,R>) in the type IntStream is not applicable for the arguments (Collector&lt;Object,capture#1-of ?,Collection&lt;Object>>)</p>
  </blockquote>
  
  <p>Any suggestions?</p>