Java Collection Tutorial - Java PriorityQueue.remove(Object o)


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

public boolean remove(Object o)


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

/*from w  ww.  j av  a  2  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) ; 
      // remove 7 from the queue
      boolean isremoved = prq.remove(7);
      System.out.println ( "Return value after remove: "+ isremoved);

The code above generates the following result.