queue is empty java code example

Example 1: java queue

import java.util.*;

Queue<Integer> queue = new LinkedList<Integer>();
// use non-primative types when constructing

// to add a value to the back of queue:
queue.add(7);

// to remove and return front value:
int next = queue.remove();

// to just return front value without removing:
int peek = queue.peek();

Example 2: how to implements an empty queue java

import java.util.*;
 
public class Main {
   public static void main(String[] args) {
    //declare a Queue   
    Queue<String> str_queue = new LinkedList<>();
    //initialize the queue with values
    str_queue.add("one");
    str_queue.add("two");
    str_queue.add("three");
    str_queue.add("four");
    //print the Queue
    System.out.println("The Queue contents:" + str_queue);
    }
}

Example 3: queue.isempty java

while (!QUEUE.isEmpty()) {
  QUEUE.remove();
 }

Tags:

Java Example