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



##########
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:
       Thanks a lot @Claudenw. One quick follow-up question. Should we consider 
replacing list.stream().filter(Objects::nonNull).collect(Collectors.toList()) 
with select( list, Object::nonNull ) or are we saying removeNullElements method 
itself isn't needed as the same can be achieved using select( list, 
Object::nonNull ) ? This would help me decide on whether I will have to 
incorporate the said comments or close this PR altogether. Thanks in advance. 




-- 
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