PriorityBlockingQueue remove() method in Java Last Updated : 26 Nov, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The remove(Object o) method of PriorityBlockingQueue is used to delete an element from this queue. This method removes a single instance of the element passed as the parameter, if it is present. It returns true if and only if the element was removed, else it returned false. Syntax: public boolean remove(Object o) Parameter: This method accepts a mandatory parameter o which is the element to be removed from this queue, if present. Return Value: This method returns true if the specified element was removed successfully. Else this method returns false. Below programs illustrate remove() method in PriorityBlockingQueue: Program 1: Java // Java Program Demonstrate remove() // method of PriorityBlockingQueue import java.util.concurrent.PriorityBlockingQueue; public class GFG { public static void main(String[] args) { // create object of PriorityBlockingQueue PriorityBlockingQueue<Integer> pbq = new PriorityBlockingQueue<Integer>(); // Add element to PriorityBlockingQueue pbq.put(1); pbq.put(2); pbq.put(3); pbq.put(4); // print queue System.out.println("Queue: " + pbq); // remove 2 boolean res = pbq.remove(2); System.out.println("\n2 removed: " + res); // print queue System.out.println("Queue: " + pbq); // remove 5 res = pbq.remove(5); System.out.println("\n5 removed: " + res); // print queue System.out.println("Queue: " + pbq); } } Output: Queue: [1, 2, 3, 4] 2 removed: true Queue: [1, 4, 3] 5 removed: false Queue: [1, 4, 3] Java // Java Program Demonstrate remove() // method of PriorityBlockingQueue import java.util.concurrent.PriorityBlockingQueue; public class GFG { public static void main(String[] args) { // create object of PriorityBlockingQueue PriorityBlockingQueue<String> pbq = new PriorityBlockingQueue<String>(); // Add element to PriorityBlockingQueue pbq.put("Geeks"); pbq.put("forGeeks"); pbq.put("A Computer"); pbq.put("Portal"); // print queue System.out.println("Queue: " + pbq); // remove Geeks boolean res = pbq.remove("Geeks"); System.out.println("\nGeeks removed: " + res); // print queue System.out.println("Queue: " + pbq); // remove SandeepJain res = pbq.remove("SandeepJain"); System.out.println("\nSandeepJain removed: " + res); // print queue System.out.println("Queue: " + pbq); } } Output: Queue: [A Computer, Portal, Geeks, forGeeks] Geeks removed: true Queue: [A Computer, Portal, forGeeks] SandeepJain removed: false Queue: [A Computer, Portal, forGeeks] Comment More infoAdvertise with us Next Article PriorityBlockingQueue put() method in Java C code_r Follow Improve Article Tags : Java Java-Collections Java - util package Java-Functions Java-PriorityBlockingQueue +1 More Practice Tags : JavaJava-Collections Similar Reads Java PriorityBlockingQueue removeAll() Method In Java, the removeAll() method of the PriorityBlockingQueue class is used to remove all elements from the queue that are also present in another specified collection. Example 1: The below Java program demonstrates the use of the removeAll() method to remove all the elements of integer type from a P 2 min read PriorityQueue remove() Method in Java The remove() method of PriorityQueue class of java.util package is used to remove a particular element from a PriorityQueue. As we all know that the elements while entering into the priority queue are not sorted but as we all know while taking out elements from the priority queue the elements are al 5 min read PriorityBlockingQueue take() method in Java The take() method of PriorityBlockingQueue returns head of the queue after removing it. If queue is empty, then this method will wait until an element becomes available. Syntax: public E take() throws InterruptedException Returns: This method returns value at the head of this PriorityBlockingQueue. 2 min read PriorityBlockingQueue size() method in Java The size() method of PriorityBlockingQueue is used to find the present size of the queue. It returns the number of elements in the collection. If the collection contains more than Integer.MAX_VALUE elements, then this method returns Integer.MAX_VALUE. Syntax: public int size() Return Value: This met 2 min read PriorityBlockingQueue put() method in Java The put(E e) method of PriorityBlockingQueue is used to add an element into this queue. This method inserts the specified element into this priority queue. Since the queue is unbounded, this method will be never be blocked.Syntax: public void put(E e) Parameter: This method accepts a mandatory param 2 min read PriorityBlockingQueue add() Method in Java The add(E e) method of PriorityBlockingQueue inserts the element passed as a parameter to the method at the tail of this PriorityBlockingQueue. This method returns true if the adding of the element is successful. Else it returns false. Syntax: public boolean add(E e) Parameter: This method takes a m 2 min read Like