From the Javadoc for Deque:
While Deque implementations are not strictly required to prohibit the insertion of null elements, they are strongly encouraged to do so. Users of any Deque implementations that do allow null elements are strongly encouraged not to take advantage of the ability to insert nulls. This is so because null is used as a special return value by various methods to indicated that the deque is empty.
I didn't find the answer in the existing question: Why can we add null elements to a java LinkedList?
null
should be reserved as a special value indicating that a value is missing or something is empty. Most collections do allow nulls, but it is advised not to add them.ListedList
is also aList
, which typically, at least for most if not all Java SEList
implementations, allow nulls.