Nope. If you could do it in constant time, you could do a comparison sort in linear time by heapifying an array and then finding the top N items, where N is all of them.

Answer from user2357112 on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › PriorityQueue.html
PriorityQueue (Java Platform SE 8 )
3 weeks ago - A priority queue relying on natural ordering also does not permit insertion of non-comparable objects (doing so may result in ClassCastException). The head of this queue is the least element with respect to the specified ordering. If multiple elements are tied for least value, the head is one of those elements -- ties are broken arbitrarily. The queue retrieval operations poll, remove, peek, and element access the element at the head of the queue.
🌐
GeeksforGeeks
geeksforgeeks.org › java › priorityqueue-peek-method-in-java
PriorityQueue peek() Method in Java - GeeksforGeeks
December 10, 2018 - The java.util.PriorityQueue.peek() method in Java is used to retrieve or fetch the first element of the Queue or the element present at the head of the Queue. The element retrieved does not get deleted or removed from the Queue.
🌐
Medium
medium.com › @AlexanderObregon › javas-priorityqueue-peek-method-explained-44363f4fd1c0
Java’s PriorityQueue.peek() Method Explained | Medium
January 9, 2025 - Using peek() allows the system to preview the next job for logging or monitoring purposes while preserving the order of the queue. import java.util.PriorityQueue; class Job implements Comparable<Job> { String id; int priority; public Job(String ...
🌐
TutorialsPoint
tutorialspoint.com › home › java/util › java priorityqueue peek
java.util.PriorityQueue.peek() Method
February 13, 2026 - The following example shows the usage of java.util.PriorityQueue.peek() package com.tutorialspoint; import java.util.*; public class PriorityQueueDemo { public static void main(String args[]) { // create priority queue PriorityQueue < Integer > prq = new PriorityQueue < Integer > (); // insert values in the queue for ( int i = 3; i < 10; i++ ) { prq.add (new Integer (i)) ; } System.out.println("Initial priority queue values are: "+ prq); // get the head from the queue Integer head = prq.peek(); System.out.println("Head of the queue is: "+ head); } } Let us compile and run the above program, this will produce the following result.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › util › PriorityQueue.html
PriorityQueue (Java Platform SE 7 )
A priority queue relying on natural ordering also does not permit insertion of non-comparable objects (doing so may result in ClassCastException). The head of this queue is the least element with respect to the specified ordering. If multiple elements are tied for least value, the head is one of those elements -- ties are broken arbitrarily. The queue retrieval operations poll, remove, peek, and element access the element at the head of the queue.
🌐
Codecademy
codecademy.com › docs › java › priorityqueue
Java | PriorityQueue | Codecademy
May 11, 2025 - A PriorityQueue can be traversed with a for-each loop. Items will be returned in the order they were inserted, not in priority order. ... The .peek() method retrieves the head of the queue without removing it, while .poll() retrieves and removes it.
🌐
GeeksforGeeks
geeksforgeeks.org › java › priority-queue-in-java
PriorityQueue in Java - GeeksforGeeks
A PriorityQueue in Java is a queue where elements are ordered based on their priority, rather than the order of insertion. By default, it uses natural ordering (min-heap), but a custom comparator can be used to define different priorities.
Published   3 weeks ago
Find elsewhere
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › util › PriorityQueue.html
PriorityQueue (Java SE 11 & JDK 11 )
January 20, 2026 - A priority queue relying on natural ordering also does not permit insertion of non-comparable objects (doing so may result in ClassCastException). The head of this queue is the least element with respect to the specified ordering. If multiple elements are tied for least value, the head is one of those elements -- ties are broken arbitrarily. The queue retrieval operations poll, remove, peek, and element access the element at the head of the queue.
🌐
DigitalOcean
digitalocean.com › community › tutorials › priority-queue-java
Priority Queue Java | DigitalOcean
August 4, 2022 - The offer() and add() methods are ... throw an exception even if it fails to add the element in the queue. E peek() - Retrieves the head of this queue, or returns null if this queue is empty....
🌐
Educative
educative.io › answers › what-is-the-priorityqueuepeek-method-in-java
What is the PriorityQueue.peek() method in Java?
The return value of the PriorityQueue.peek()method depends on the following conditions: If the PriorityQueue is not empty, it returns an element present at the head of the PriorityQueue. If the PriorityQueue is empty, it returns a NULL value. ... Line 1: We imported the required package. Line 2: We have a Main class as Java ...
🌐
Baeldung
baeldung.com › home › java › java collections › guide to java priorityqueue
Guide to Java PriorityQueue | Baeldung
January 8, 2024 - As we may infer from its name, ... element with respect to the ordering we specify. Every retrieval operation of the queue (poll, remove, or peek) reads the head of the queue....
🌐
Dot Net Perls
dotnetperls.com › priorityqueue-java
Java - PriorityQueue Example - Dot Net Perls
0) { // Get polled element and print it. int polled = queue.poll(); System.out.println(polled); } } } ... With PriorityQueue we can access a collection in a sorted order, even without sorting it. We call peek() and poll() to get the first-sorted element. And This can simplify code.
🌐
CodeGym
codegym.cc › java blog › java collections › java priority queue: not a classical queue
Java Priority Queue: not a classical queue
January 16, 2025 - Object element() retrieves the head of this queue without removing it. Throws NoSuchElementException if the queue is empty. Object peek() retrieves the head of the queue without removing it.
🌐
Medium
medium.com › @greekykhs › all-about-priorityqueue-in-java-d5220dee7feb
A Guide to PriorityQueue in Java. What is PriorityQueue in Java? | by Himaanshu Shukla | Medium
July 6, 2024 - PriorityQueue(SortedSet c): Creates a PriorityQueue containing the elements in the specified sorted set. ... public peek() retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
🌐
Java67
java67.com › 2015 › 07 › how-to-use-priorityqueue-in-java-example.html
PriorityQueue in Java? Example Tutorial | Java67
If you remember, the Queue interface provides two sets of methods for similar tasks e.g. add() and offer() for adding elements, poll() and remove() for removing a head element from PriorityQueue and peek() and element() for retrieving the head of the queue without removing. The difference between these two sets of the method is that one throws an exception if failed while the other return special values e.g. false or null if failed. This is also the reason why PriorityQueue doesn't allow adding null elements because then you cannot differentiate between the normal object and the special value. You can also read Core Java Volume 1 - Fundamentals by Cay S.
🌐
Stack Overflow
stackoverflow.com › questions › 47884563 › why-priorityqueue-peek-returns-null-when-priorityqueue-size-0
android - Why PriorityQueue.peek() returns null, when PriorityQueue.size() > 0 - Stack Overflow
Check what's inside jobs queue. Because based on Java documentation (https://docs.oracle.com/javase/8/docs/api/java/util/PriorityQueue.html) - peek() should retrieve "<...> the head of this queue, or returns null if this queue is empty.".
🌐
LMU
cs.lmu.edu › ~ray › notes › pqueues
Priority Queues
There’s already a PriorityQueue class in the Java Core API. It implements the Queue interface, and has the following characteristics: It is implemented with a heap. It uses the element type’s natural ordering or a comparator passed to the constructor. The highest priority element is the smallest element. add(), offer(), poll(), and remove() run in $\Theta(\log n)$ time. peek(), element(), and size() run in $\Theta(1)$ time.