Java queues don't have enqueue and dequeue methods, these operations are done using the following methods:
Enqueuing:
add(e): throws exception if it fails to insert the objectoffer(e): returns false if it fails to insert the object
Dequeuing:
remove(): throws exception if the queue is emptypoll(): returns null if the queue is empty
Take a look to the first object in the queue:
element(): throws exception if the queue is emptypeek(): returns null if the queue is empty
The add method, which Queue inherits from Collection, inserts an element unless it would violate the queue's capacity restrictions, in which case it throws
IllegalStateException. The offer method, which is intended solely for use on bounded queues, differs from add only in that it indicates failure to insert an element by returning false.
(see: http://docs.oracle.com/javase/tutorial/collections/interfaces/queue.html)
You can also check this as this is more useful:
http://docs.oracle.com/cd/B10500_01/appdev.920/a96587/apexampl.htm
Answer from Manish Doshi on Stack OverflowJava queues don't have enqueue and dequeue methods, these operations are done using the following methods:
Enqueuing:
add(e): throws exception if it fails to insert the objectoffer(e): returns false if it fails to insert the object
Dequeuing:
remove(): throws exception if the queue is emptypoll(): returns null if the queue is empty
Take a look to the first object in the queue:
element(): throws exception if the queue is emptypeek(): returns null if the queue is empty
The add method, which Queue inherits from Collection, inserts an element unless it would violate the queue's capacity restrictions, in which case it throws
IllegalStateException. The offer method, which is intended solely for use on bounded queues, differs from add only in that it indicates failure to insert an element by returning false.
(see: http://docs.oracle.com/javase/tutorial/collections/interfaces/queue.html)
You can also check this as this is more useful:
http://docs.oracle.com/cd/B10500_01/appdev.920/a96587/apexampl.htm
You have not initialized myQueue:
Queue myQueue;
Note that Queue is an abtract class,you need initialize myQueue to the appropriate implementation.
Refer below javaDoc:
http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Queue.html