title: Java 8 lambda null list to empty check
body: <p>I am trying to do <code>null</code> check for the list of values and change it to empty if the value is <code>null.</code>I am getting null as one of the list of value in x.getSomeCall().The null value is not getting added as empty list in the new list</p>
  
  <pre><code>public class Example{
       private List&lt;Test&gt; test;
       //setter
       //getter
  }
  
  public class Test{
      private List&lt;Test2&gt; test2;
       //setter
       //getter
  }
  
  public class Test2{
      private String name;
      //setter
      //getter
  }
  
  public static void main(String args[]){
  </code></pre>
  
  <p>Example example=new Example();
  example.setTest(test);</p>
  
  <pre><code>    List&lt;Test&gt; test=new ArrayList&lt;&gt;();
      Test t=new Test();
      t.setTest2(test);
      Test t1=new Test();
      Test t2=new Test();
      test.add(t);
      test.add(t1);
  
      List&lt;Test2&gt; test=new ArrayList&lt;&gt;();
      Test2 t=new Test2();
      test.add(t);
      test.add(null); // I want to get these value as empty list along with the 1st Value in a new list
  
  //Imperative Programming
  for(Example ex:example.getTest()){
  System.out.println(ex.getTest2());/It prints t object and a null vale
  
  }
  
  
  When I tried the same with reactive
  
  List&lt;Test2&gt; t=example.getTest().stream()
                                .flatMap(x -&gt; x.getTest2() == null ? Stream.empty() : x.getTest2().stream())
                                .collect(Collectors.toList());
  
          System.out.println(t)// It prints only t object
  I was expecting two element on with t object and the other one as empty list[]
  
  }
  </code></pre>
  
  <p>So that later I can do an empty check with the new list</p>
  
  <pre><code> if(isEmpty(example.getTest().stream()
                                    .flatMap(x -&gt; x.getTest2() == null ? Stream.empty() : x.getTest2().stream())
                                    .collect(Collectors.toList())))
  </code></pre>