Java PriorityQueue.remove(Object o)

Syntax

PriorityQueue.remove(Object o) has the following syntax.

public boolean remove(Object o)

Example

In the following code shows how to use PriorityQueue.remove(Object o) method.


//  w  ww.j  a  v a2  s.c o  m
import java.util.PriorityQueue;

public class Main {
   public static void main(String args[]) {

      PriorityQueue<Integer>   prq = new PriorityQueue<Integer>(); 
       
      // insert values in the queue
      for ( int i = 3; i < 10; i++ ){  
         prq.add (i) ; 
      }
      
      System.out.println(prq);
      
      // remove 7 from the queue
      boolean isremoved = prq.remove(7);
      
      System.out.println ( "Return value after remove: "+ isremoved);
      
      System.out.println(prq);
   }
}

The code above generates the following result.