I'm studying for the OCP. From what I understand, a Deque has three methods that can remove an element from the left of a deque:
1. poll() - returns null for an empty list
2. remove() - throws an exception for an empty list
3. pop() - throws an exception for an empty list
Is there a difference between remove() and pop() when dealing with a Deque?
I don't think there is a difference. I've checked the four known Deque implementations (ArrayDeque, ConcurrentLinkedDeque, LinkedBlockingDeque, LinkedList), and all delegate to removeFirst from both the remove and pop methods.
The only difference is their source, because Sun managed to conflate stacks and queues when they designed ArrayDeque in Java6. Those of us who have done stack programming would have this sort of inheritance hierarchyCounting errors in that diagram is left as an exercise to the reader
The Queue/Deque interfaces would have offer() poll() peek() and similar methods; the Stack interface would have push() pop() peek() methods and wouldn't extend Collection. Unfortunately they shot themselves in the foot with public class Stack extends Vector and they have never recovered from that error. The pop() method comes from the usual concepts of a stack, and that is the one difference.
I notice that peek() seems to appear in both queues and stacks, but there is a difference between the two versions of peek(), too. that in a Queue seems to return null from an empty Queue and that in the Stack class throws an exception.