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?
Such provisions are allowed to make programmers life easier. I can think of an example.
Suppose there is a linkedList of houses and a postMan comes to deliver letters to each house in sequence. Each Node in linkedList present house. Houses have a family object as their value. In some cases family may not be there then house object will have null value.
But for postman it is not relevant as he still has to visit that node. PostOffice has the suggestion to all families to indicate postoffice if they are leaving the house so that postMan need not to visit that house(if possible).
But for some purpose house owner decide to not inform postOffice about this situation and wish to continue receiving letters(indirectly a postman visit).
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