My question is regarding the fact that an ArrayDeque does not accept null values. The OCP study guide states the following: "You can’t put null in an ArrayDeque because methods like poll() use null as a special return value to indicate that the collection is empty. Since null has that meaning, Java forbids putting a null in there. That would just be confusing." I understand that but then why is it allowed for a LinkedList to accept null values. I would expect a LinkedList to reject null values as well because it also uses methods like poll()?
Start by going through the documentation for linked list and array deque. Also the Java™ Tutorials. Please tell us which guide (including authors and page number) you are quoting.
The two classes were designed about eight years apart. The ordinary linked list is intended as a List and Lists usually accept nulls. A linked list can also be used as a queue, but that is not its primary intent. ArrayDeque was designed as a Deque, not a list, so returning null from an empty queue would be confusing. And avoiding confusion is a good way to design an API.
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
Create Edit Print & Convert PDF Using Free API with Java