When I try:
Queue<Integer> q = new Queue<Integer>();
The compiler is giving me an error. Any help?
Also, if I want to initialize a queue do I have to implement the methods of the queue?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
Queueis an interface, which means you cannot construct aQueuedirectly.The best option is to construct off a class that already implements the
Queueinterface, like one of the following:AbstractQueue,ArrayBlockingQueue,ArrayDeque,ConcurrentLinkedQueue,DelayQueue,LinkedBlockingQueue,LinkedList,PriorityBlockingQueue,PriorityQueue, orSynchronousQueue.An alternative is to write your own class which implements the necessary Queue interface. It is not needed except in those rare cases where you wish to do something special while providing the rest of your program with a
Queue.An even less used alternative is to construct an anonymous class that implements
Queue. You probably don’t want to do this, but it’s listed as an option for the sake of covering all the bases.