title: How to remove null or empty list from an "unmodifiable" map
body: <p>I have an unmodifiable map (<code>Map&lt;String, Object&gt;</code>). This contains a key-value pair, where the value should be a List, but for a specific key the value is an empty List. </p>
  
  <p>How can I remove that empty list from the map and return? </p>
  
  <p>I have done it using predicate which checks if the value is an instance of collection and then check if Collections.isNotEmpty(..). </p>
  
  <p>I want to know is there any better approach than this? (In Java 8)</p>
  
  <pre><code>public class StudentTest {
  
      Predicate&lt;Object&gt; isCollectionNotEmpty = input -&gt; {
          if (input instanceof Collection) {
              return CommonCollectionUtils.isNotEmpty((Collection&lt;?&gt;)input);
          }
          return true;
      };
      Predicate&lt;Object&gt; isObjectNotNull = input -&gt; Objects.nonNull(input);
  
      public static void main(String[] args) {
  
          StudentTest s = new StudentTest();
          final Map&lt;String, Object&gt; map1 = new HashMap&lt;&gt;();
          map1.put("student_batch_size", 200);
          map1.put("student_avg_height", 172);
          map1.put("Student_names", Collections.emptyList());
  
          final Map&lt;String, Object&gt; finalMap = s.getFinalMap(Collections.unmodifiableMap(map1));
  
          System.out.println(finalMap);
      }
  
      private Map&lt;String, Object&gt; getFinalMap(final Map&lt;String, Object&gt; inputMap) {
          final Map&lt;String, Object&gt; resultMap = new HashMap&lt;&gt;();
          //inputMap.values().remove(Collections.emptyList());
          resultMap.putAll(inputMap.entrySet().stream()
              .filter(entry -&gt; isObjectNotNull.and(isCollectionNotEmpty).test(entry.getValue()))
          .collect(Collectors.toMap(e -&gt; e.getKey(), e -&gt; e.getValue())));
          return resultMap;
      }
  
  }
  </code></pre>
  
  <p>Expected Output: </p>
  
  <pre><code>{student_avg_height=172, student_batch_size=200}
  </code></pre>