Retrieves, but does not remove, the head of the queue represented by this deque, or returns
null
if this deque is empty.
package com.logicbig.example.arraydeque;
import java.util.ArrayDeque;
import java.util.List;
public class PeekExample {
public static void main(String... args) {
ArrayDeque<Integer> ad = new ArrayDeque<>(List.of(3, 8, 5, 7));
System.out.println(ad);
Integer element = ad.peek();
System.out.println(element);
System.out.println(ad);
}
}
Output
[3, 8, 5, 7]
3
[3, 8, 5, 7]