Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Stuart Keenan3,131 Points
Queue vs Deque
I understand the Double-ended queue part of a Deque. It comes with the options to pull and remove from both ends of the queue, but for the Karaoke Machine project we are only pulling from the head of the queue and adding to the tail. Wouldn't it be less compiler intensive to just make a Queue then for our song list? Is the reason for doing this because Deque offers the ability to check the size while queue does not (can anyone explain why this is?)?
Is the reason for doing this because Deque offers the ability to check the size while queue does not (can anyone explain why this is?)?
No, that isn't the reason.
In Java Collections Framework, Queue is a Java interface http://docs.oracle.com/javase/7/docs/api/java/util/Queue.html. Since Queue is an interface, you can't instantiate a Queue object.
To do that you have to use the ArrayDeque Java class (which implements the Queue interface). http://docs.oracle.com/javase/7/docs/api/java/util/ArrayDeque.html
My guess is that they choose to use a Deque over the other classes that implement Queue because Deque's are very robust and versatile (adding and removing from front/head and tail/back vs. a LinkedList which can only add and remove from back/tail).
Wouldn't it be less compiler intensive to just make a Queue
Even if there was a Queue class, for a small program like this, Queue vs. Deque doesn't really matter.