What is the best way to make null-safe contains in a Java collection?
In other words -
if (collection != null && collection.contains(x))
?
I was hoping that in Apache collection collections there is something like CollectionUtils.contains(collection, x) which will simply return false if the collection was null, as it is with size() , which treats null as an empty collection.
However, there seems to be no such thing - did I just skip it?
wrschneider
source share