title: Java 8: Stream a list and map to another list based on different filters
body: <p>I have the following 
  code:</p>
  
  <pre><code>public boolean foo(List&lt;JSONObject&gt; source, String bar, String baz) {
      List&lt;String&gt; myList = newArrayList();
  
      source.forEach(json -&gt; {
          if (!(json.get(bar) instanceof JSONObject)) {
              myList.add(json.get(bar).toString());
          } else {
              myList.add(json.getJSONObject(attribute).get("key").toString());
          }
      });
  
      /**
       * do something with myList and baz
       */
  }
  </code></pre>
  
  <p>I'm just wondering if there's a way to do the <code>if-else</code> condition inline using a filter.</p>
  
  <p>Something along the lines of:</p>
  
  <pre><code>List&lt;String&gt; myList = source.stream()
                  .filter(json -&gt; !(json.get(bar) instanceof JSONObject))
                  .map(item -&gt; item.get(attribute).toString())
                  .collect(Collectors.toList());
  </code></pre>
  
  <p>If I go by the approach above, I will miss the supposed to be "else" condition. How can I achieve what I want using a more <code>java-8</code> way? </p>
  
  <p>Thanks in advance!</p>