Java Collections Java Java API
java.util.PriorityQueue
public E peek()
Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
null
package com.logicbig.example.priorityqueue;import java.util.PriorityQueue;public class PeekExample {//public E peek() public static void main(String... args) { PriorityQueue<String> pq = new PriorityQueue<>(); pq.offer("one"); pq.offer("two"); System.out.println(pq); String element = pq.peek(); System.out.println(element); element = pq.peek(); System.out.println(element); }}
[one, two]oneone