title: Java8: Filter and map on same method output
body: <p>We are trying to refactor below code to java 8:</p>
  <pre><code>List&lt;String&gt; list = new ArrayList&lt;&gt;();
  Iterator&lt;Obj&gt; i = x.iterator();
  while (i.hasNext()) {
     String y = m(i.next().getKey());
     if (y != null) {
        list.add(y);
     }
  }
  return list;
  </code></pre>
  <p>So far we have come up with:</p>
  <pre><code>return x.stream()
    .filter(s -&gt; m(s.getKey()) != null)
    .map(t -&gt; m(t.getKey()))
    .collect(Collectors.toList());
  </code></pre>
  <p>But the method <code>m()</code> is being invoked twice here. Is there any way around?</p>