Claudenw commented on a change in pull request #267:
URL:
https://github.com/apache/commons-collections/pull/267#discussion_r758465731
##########
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:
How about `ListUtils.select( list, Object::nonNull )` ??
--
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]