title: How can I replace any instances of null with an empty List in my stream?
body: <p>In my method below, the variable <code>n</code> can be null, and if it is null I want to return an empty list eg something like <code>List.of</code>. How can I amend the below method to ensure that if a null is found, an empty <code>List</code> is returned and not removed? I tried using <code>filter</code> which I've commented out below, but that just removes any instances where null is found.</p>
  <pre><code>    private List&lt;Account&gt; getNames(MetaData metadata){
      return metadata.getNames()
            .stream()
            .map(n -&gt; createAccount(n, metadata.getType()))
            //.filter(n -&gt; n.getFinalName() != null)
            .collect(Collectors.toList());
      } 
  
  private Account createAccount(String n, Metadata metadata){...}
  </code></pre>