I'm looking for a class from the Java Collection Framework that would not allow null elements.
Do you know one?
Use Constraints
:
import com.google.common.collect.Constraints; ... Constraints.constrainedList(new ArrayList(), Constraints.notNull())
from Guava for maximum flexibility.
UPDATE: Guava Constraints has been deprecated in Release 15 - apparently without replacement.
UPDATE 2: As of now (Guava 19.0-rc2) Constrains is still there and not deprecated anymore. However, it's missing from the Javadoc.
I'm afraid that the Javadoc is right as MapConstraint
have been deprecated in Release 19, too
Most Queue
implementations (with the notable exception of LinkedList
) don't accept null
.
EnumSet
is a special-purpose Set
implementation that doesn't allow null
values.
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