A
Arne Vajhøj
Why? why use a Deque instead of a Stack? ... because the documentation
says so? ...
The authors of that documentation is the authors of the code.
It seems reasonable to expect them to know the domain pretty well.
A Stack is an abstraction, it's a very widely understood
abstraction, everyone who has ever read a book on software knows what a
stack is. push, pop, peek, they are Stack methods, you don't need
anything else for a Stack, even peek is questionable. Providing a method
to add something to the bottom of a Stack doesn't make sense in terms of
the 'stackness' of a Stack. It just adds meaningless and unneeded
complexity and confusion, particularly for a beginner to Java.
If you are reading someone else's code and you see
Stack s = new Stack();
you know EXACTLY what to expect. What are you to expect when you see a
Deque ... could be anything.
People reading Java Docs will know what it is.
People with CS background will know what a double ended queue is.
Arne