title: Using a stream to iterate n times instead of using a for loop to create n items
body: <p>Say I want to create n items. Pre Java 8, I would write:</p>
  
  <pre><code>List&lt;MyClass&gt; list = new ArrayList&lt;&gt;();
  for (int i = 0; i &lt; n; i++) {
      list.add(new MyClass());
  }
  </code></pre>
  
  <p>Is there an elegant way to use a stream to create n items?<br>
  I thought of this:</p>
  
  <pre><code>List&lt;MyClass&gt; list = Stream.iterate(0, i -&gt; i).limit(10)
      .map(o -&gt; new MyClass()).collect(Collectors.toList());
  </code></pre>
  
  <p>Is there a standard/better way of coding this?</p>
  
  <p>Note that the <em>actual</em> usage is a bit more complex and using a stream would be more flexible because I can immediately pump the items through other functions in one line without even creating a reference to the list, for example grouping them:</p>
  
  <pre><code>Stream.iterate(0, i -&gt; i).limit(10).map(o -&gt; new MyClass())
      .collect(Collectors.groupingBy(...));
  </code></pre>