Java Collections Java Java API
Class:
java.util.PriorityQueue
Method:
public E peek()
Retrieves,
but does not remove, the head of this queue, or returns
null
if this queue is empty.
Examples
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); } }
Output[one, two] one one
|
|