Java SE API

Queue.poll()

Remove and return the head, or null when empty. Ordering depends on implementation.

Formal Syntax & Structure

java syntaxjava
E poll()

Return Value

E

Removed head, or null when empty.

Working Example

Example Snippetjava
import java.util.*;public class Main {
    public static void main(String[] args) {        Queue<String> pending = new ArrayDeque<>();        pending.offer("R1"); pending.offer("R2");        System.out.println(pending.peek());        System.out.println(pending.poll());        System.out.println(pending.poll());        System.out.println(pending.poll());    }}
Java Reference