Java PriorityQueue.contains(Object o)

Syntax

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

public boolean contains(Object o)

Example

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


import java.util.PriorityQueue;
/*from w w w  .ja  va  2s .co m*/
public class Main {
   public static void main(String args[]) {

      PriorityQueue<Integer>   prq = new PriorityQueue<Integer>(); 
       
      for ( int i = 0; i < 10; i++ ){  
         prq.add(i) ; 
      }
      
      System.out.println(prq);
      
      // check if queue contains 5
      boolean b = prq.contains(5);
      
      System.out.println ( "Priority queue contains 5: " + b);
   }
}

The code above generates the following result.