Is there a viable generic version of org.apache.commons.collections.CollectionUtils
? If not, why not? It seems like an obvious need. Or has the Java community just given up on functional coding until closures are added to Java 17?
Simply put, the Apache CollectionUtils provides utility methods for common operations which cover a wide range of use cases and helps in avoiding writing boilerplate code. The library targets older JVM releases because currently, similar functionality is provided by the Java 8's Stream API.
Apache Commons Collections - Overview Commons Collections augments Java Collections Framework. It provides several features to make collection handling easy. It provides many new interfaces, implementations and utilities.
The Apache Commons Collections are the components of the Apache Commons which are derived from Java API and provides component architecture for the Java language. Commons-Collections seek to build upon the JDK classes by providing new interfaces, implementations and utilities.
isNotEmpty() method of CollectionUtils can be used to check if a list is not empty without worrying about null list. So null check is not required to be placed everywhere before checking the size of the list.
There's a genericified port of a slightly out-of-date version of Commons Collections here. It's no longer maintained, however.
A better option is Google Guava. It has classes like Lists
, Sets
, Collections2
etc that are the equivalent to Commons' CollectionUtils
. Guava is not a one-for-one port of Commons Collections, but it has a better designed and more consistent API. Takes a bit of adjusting to, if you're used to Commons Collections.
Looks like situation around Apache Commons Collections has changed. API version 4.0 is strongly typed. It is already available in Maven Central Repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With