Open In App

How to Check if a PriorityQueue is Empty or Contains Elements in Java?

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will demonstrate how to check if a Priority Queue is empty or not. The java.util.PriorityQueue.isEmpty() method is used to check if the Priority Queue is empty or not. Based on the Boolean value it returns the Response for the same.

Syntax:

Priority_Queue.isEmpty()

Parameters: There is no need to pass any parameter inside the function.

Return Value: The method returns a boolean value, ie. True if Priority Queue is empty else false.

Program to Check if a PriorityQueue is Empty

The below programs illustrate the Java.util.PriorityQueue.isEmpty() method:

Example 1:

The program showing that the PriorityQueue is not Empty:


Output
false

Example 2:

The program showing that the PriorityQueue is Empty:


Output
true

Similar Reads