The queue.remove()
function in Java returns the element available at the front of the queue and removes that element from the queue.
Figure 1, below, shows the visual representation of the queue.remove()
function.
The following module is required to use the java.util.*
function.
element queue_name.remove();
// where the queue_name is the name of the queue
This function does not require a parameter.
This function returns the element
available at the front of the queue and removes that element
from the queue.
import java.util.*;class JAVA {public static void main( String args[] ) {Queue<Integer> Queue = new LinkedList<Integer>();Queue.add(1);Queue.add(3);Queue.add(5);Queue.add(2);Queue.add(0);//Queue = 1->3->5->2->0System.out.println("Following are the elements in Queue before removing: " + Queue);System.out.println("The element removed from the front of Queue: "+Queue.remove());System.out.println("Following are the elements in Queue after removing: " + Queue);}}