title: Java: replace forEach loop with stream
body: <p>In the following method I want to replace the forEach loop with a stream.</p>
  
  <pre><code>protected Set&lt;String&gt; getSelectedPaths(final CheckModel&lt;TreeItem&lt;String&gt;&gt; checkModel, final LazyTreeItem root) {
  
        final Set&lt;String&gt; ceckedList = new HashSet&lt;&gt;();
        final List&lt;TreeItem&lt;String&gt;&gt; children = root.getChildren();
        final List&lt;LazyTreeItem&gt; lazyChildren = children.stream().map((item -&gt; (LazyTreeItem) item))
              .collect(Collectors.toList());
  
        final List&lt;String&gt; selectedChildren = new ArrayList&lt;&gt;();
        children.forEach(child -&gt; selectedChildren.addAll(getSelectedPaths(checkModel, (LazyTreeItem) child)));
  
        /**
        * do sth with checkedList
        */
       return checkedList
  </code></pre>
  
  <p>the lines </p>
  
  <pre><code>      final List&lt;String&gt; selectedChildren = new ArrayList&lt;&gt;();
        children.forEach(child -&gt; selectedChildren.addAll(getSelectedPaths(checkModel, (LazyTreeItem) child)));
  </code></pre>
  
  <p>should be replaced with a stream. I tried with </p>
  
  <pre><code>      final List&lt;String&gt; selectedChildren = children.stream().map(child-&gt;getSelectedPaths(checkModel, (LazyTreeItem) child)).collect(Collectors.toList());
  </code></pre>
  
  <p>but the compiler error "<code>
  Type mismatch: cannot convert from List&lt;Set&lt;String&gt;&gt; to List&lt;String&gt;"</code>
   is thrown.
  Is there an opportunity to replace this forEach loop with a stream?</p>