garydgregory commented on a change in pull request #267:
URL: 
https://github.com/apache/commons-collections/pull/267#discussion_r757803836



##########
File path: src/main/java/org/apache/commons/collections4/ListUtils.java
##########
@@ -744,6 +745,23 @@ public static String longestCommonSubsequence(final 
CharSequence charSequenceA,
         return UnmodifiableList.unmodifiableList(list);
     }
 
+    /**
+     * Returns a new list by removing all null elements from the given list.
+     *
+     * @param <E> the element type
+     * @param list  the input list, must not be null and must not be empty
+     * @return a new list by removing all null elements from the given list
+     * @throws NullPointerException if the input list is null
+     * @throws IllegalArgumentException if the input list is empty
+     */
+    public static <E> List<E> removeNullElements(final List<E> list) {
+       Objects.requireNonNull(list, "input list must not be null");
+        if (list.size() == 0) {
+            throw new IllegalArgumentException("input list must not be empty");
+        }
+        return 
list.stream().filter(Objects::nonNull).collect(Collectors.toList());
+    }

Review comment:
       I agree with @kinow that it does not seem worth it. The argument that 
Bruno's example requires a list to be created seems beside the point, because 
the PR creates a stream, a lambda, a filter and so on. In my experience, I 
usually end up with putting a non-null filter in the middle of stream 
processing which ends up best since I don't have to go back and forth between 
streams and collections.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to