title: When using Collectors.toMap in Java, how would I skip adding an entry to the new map?
body: <p>So here's my code:</p>
  
  <pre><code>HashMap&lt;String, List&lt;Foo.Builder&gt;&gt; strFooMap = new HashMap&lt;&gt;();
  // add stuff to strFooMap and do other things
  return new HashMap&lt;&gt;(strFooMap.entrySet()
      .stream()
      .collect(Collectors.toMap(Entry::getKey,
          entry -&gt; entry
              .getValue()
              .stream()
              .filter(builder -&gt; {
                // do some conditional stuff to filter
              })
              .map(builder -&gt; {
                return builder.build();
              })
              .collect(Collectors.toList())
          )
      )
  );
  </code></pre>
  
  <p>So sometimes, after doing the <code>filter</code>, all the items in my <code>List&lt;Foo.Builder&gt;</code> will be filtered out. Then in my final <code>HashMap</code>, I have an entry like this: <code>{"someStr" -&gt; []}</code>. I would like to remove the key value pairs where the value is an empty list. How would I go about doing this? Would it be possible to do this while in the <code>.stream().collect(Collectors.toMap(...))</code> code? Thanks!</p>