Java SE API
Queue.peek()
Inspect the head without removing it, or return null when empty.
Formal Syntax & Structure
java syntaxjava
E peek()Return Value
E
Head without removal, 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()); }}