How do I instantiate a Queue object in java?

后端 未结 8 748
南旧
南旧 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 16:56

    Queue is an interface in java, you can not do that.

    Instead you have two options:

    option1:

    Queue Q = new LinkedList<>();
    

    option2:

    Queue Q = new ArrayDeque<>();
    

    I recommend using option2 as it is bit faster than the other

提交回复
热议问题