Create a queue using LinkedList class : Queue « Collections « Java Tutorial






import java.util.LinkedList;
import java.util.Queue;

public class Main {
  public static void main(String[] args) {
    Queue<String> queue = new LinkedList<String>();
    queue.offer("First");
    queue.offer("Second");
    queue.offer("Third");
    queue.offer("Fourth");

    System.out.println("Size: " + queue.size());

    System.out.println("Queue head using peek   : " + queue.peek());
    System.out.println("Queue head using element: " + queue.element());

    Object data;
    while ((data = queue.poll()) != null) {
      System.out.println(data);
    }
  }
}








9.14.Queue
9.14.1.Convert a Queue to a List
9.14.2.Use the Stack class in Java
9.14.3.Create a queue using LinkedList class
9.14.4.Checking what item is first in line without removing it: element
9.14.5.A Priority Queue
9.14.6.Binary Heap Queue
9.14.7.Circular Queue
9.14.8.Synchronized Queue