I was looking around for some elegant solution to removing null values from a List. I came across the following post, which says I can use list.removeAll(Collections.singletonList(null));
This, however, throws an UnsupportedOperationException
, which I'm assuming is because removeAll()
is attempting to do some mutative operation on the immutable singleton collection. Is this correct?
If this is the case, what would be a typical use of this singletonList
? To represent a collection of size 1 when you're sure you don't want to actually do anything with the collection?
Thanks in advance.