elegant way to add non-values to Map in java 8?
<p>I am using immutable map </p>

<pre><code>public Map&lt;String,String&gt; getMap(){
        return ImmutableMap.&lt;String,String&gt;builder()
                .put("FOO",getFooType())
                .put("BAR", getBarType())
                .build();
    }
</code></pre>

<p>In some cases, <code>getFooType()</code> or <code>getBarType()</code> would return null. That causes exception to be thrown from  <code>com.google.common.collect.ImmutableMap</code>. I am wondering if there is an elegant way to populate the map only with non-null and non-empty strings.</p>

<p>I am ok with any Map implementation, not confined to guava library.</p>

<p>I could do away with the following</p>

<pre><code>Map&lt;String,String&gt; map = new HashMap&lt;&gt;();

String fooType = getFooType();
String barType = getBarType();

if (fooType!=null &amp;&amp; fooType.length()&gt;0){
    map.put("FOO", fooType);
}

if (barType!=null &amp;&amp; barType.length()&gt;0){
     map.put("BAR", barType);
}
</code></pre>

<p>Since I have many keys to be added to the map, this kind of if-checks make the code not pretty. I am wondering if there is any elegant way to do it.</p>

<p>I am using Java 8 for my project.</p>