title: Java stream to collection for nullable string list
body: <p>I have a list that may be null. 
  I would like to concatenate the strings in that list into one string.</p>
  
  <p>eg. A<br>
  list = ["hello","there"]<br>
  desired output = "hello.there."</p>
  
  <p>eg. B<br>
  list = null<br>
  desired output = null</p>
  
  <p>I have a method that works for non-null lists:</p>
  
  <pre><code>List&lt;String&gt; myStringList = foo.getlist();
  String result = myStringList.stream()
              .collect(Collectors.joining(".","","."));
  </code></pre>
  
  <p>but the stream will throw an error if myStringList is null.</p>
  
  <p>I believe I should be using an optional stream similar to:</p>
  
  <pre><code>List&lt;String&gt; myStringList = foo.getlist();
  String result = Optional.ofNullable(myStringList)
      .map(Arrays::stream)
      .orElseGet(Stream::empty)
      .collect(Collectors.joining(".","","."))
  </code></pre>
  
  <p>However when I try this i get errors like "can not resolve method 'stream'".</p>
  
  <p>Am I going about this the right way?
  Why am I getting errors for the code?</p>