remove(Object): This method is available in java.util.PriorityQueue class of Java.
Syntax:
boolean java.util.PriorityQueue.remove(Object o)
This method takes one argument. This method removes a single instance of the specified element from this queue, if it is present.
Parameters: One parameter is required for this method.
o: element to be removed from this queue, if present.
Returns: true if this queue changed as a result of the call.
Exceptions: NA
Approach
Java
import java.util.PriorityQueue;public class PriorityQueueremove2 {public static void main(String[] args) {PriorityQueue<Integer> priorityQueue =new PriorityQueue<Integer>();priorityQueue.add(12);priorityQueue.add(5);priorityQueue.add(10);priorityQueue.add(2);Object o = 5;System.out.println(priorityQueue.remove(o));}}
Output:
true
No comments:
Post a Comment