How do I instantiate a Queue object in java?

后端 未结 8 749
南旧
南旧 2020-11-29 16:39

When I try:

Queue q = new Queue();

the compiler is giving me an error. Any help?

Also, if I want to i

8条回答
  •  北海茫月
    2020-11-29 17:07

    Queue is an interface. You can't instantiate an interface directly except via an anonymous inner class. Typically this isn't what you want to do for a collection. Instead, choose an existing implementation. For example:

    Queue q = new LinkedList();
    

    or

    Queue q = new ArrayDeque();
    

    Typically you pick a collection implementation by the performance and concurrency characteristics you're interested in.

提交回复
热议问题