Concatenate string values with delimiter handling null and empty strings?
<p>In Java 8 I have some number of <code>String</code> values and I want to end up with a comma delimited list of valid values.  If a <code>String</code> is <strong>null or empty</strong> I want to ignore it.  I know this seems common and is a lot like <a href="https://stackoverflow.com/questions/1642159/whats-the-most-elegant-way-to-concatenate-a-list-of-values-with-delimiter-in-ja">this old question</a>; however, that discussion does not address nulls AND spaces (I also don't like the accepted answer).</p>
<p>I've looked at Java 8 <code>StringJoiner</code>, Commons <code>StringUtils</code> (<code>join</code>) and trusty Guava (<code>Joiner</code>) but none seems like a full solution.  The vision:</p>
<pre><code> where: val1 = &quot;a&quot;, val2 = null, val3 = &quot;&quot;, val4 = &quot;b&quot;

  String niceString = StringJoiner.use(&quot;,&quot;).ignoreBlanks().ignoreNulls()
    .add(val1).add(val2).add(val3).add(val4).toString();
</code></pre>
<p>...would result in <code>niceString</code> = <code>a,b</code></p>
<p>Isn't there a nice way to do this (that doesn't involve for loops, loading strings into a list, and/or regex replaces to remove bad entries)?</p>