Checking what item is first in line without removing it: element : 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.add("A");
        queue.add("B");
        
        queue.offer("C");
        queue.offer("D");

        System.out.println("remove: " + queue.remove());

        System.out.println("element: " + queue.element());
        
        System.out.println("poll: " + queue.poll());

        System.out.println("peek: " + queue.peek());
    }
}
/*
remove: A
element: B
poll: B
peek: C

*/








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