queue vs deque vs LinkedList? Whats the difference and when to use which

Hi there, I have some questions regarding declarations and instantiations. If you can answer any of these, please help.
Sometimes I see queue, deque, LinkedList being used.

  1. How do I know when to use which one?

For instance, sometimes I see this written:

Queue<TreeNode> queue = new LinkedList<>();

or

Deque<TreeNode> dq = new ArrayDeque<>();

2) Why would I use a Queue vs a Deque?

  1. Also, for the first line, can I instead say
    Queue queue = new Queue<>();

  2. Finally, what are the rules for declaration vs instantiation? For example, if I declare as a Deque on the left side, what type can I instantiate it as on the right side?

  3. Also why am I allowed to say Queue queue = new LinkedList<>() when they are not the same type?

Comments (1)