PriorityBlockingQueue remainingCapacity() method in Java Last Updated : 07 May, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The remainingCapacity method of PriorityBlockingQueue is used to check how much more elements can be inserted into this queue. But since the PriorityBlockingQueue is unbounded, this method always returns Integer.MAX_VALUE because a PriorityBlockingQueue is not capacity constrained.Syntax: public int remainingCapacity() Return Value: Integer.MAX_VALUE alwaysBelow programs illustrate remainingCapacity() method in PriorityBlockingQueue:Program 1: Java // Java Program Demonstrate remainingCapacity() // method of PriorityBlockingQueue import java.util.concurrent.PriorityBlockingQueue; public class GFG { public static void main(String[] args) { // define capacity of PriorityBlockingQueue int capacityOfQueue = 7; // create object of PriorityBlockingQueue PriorityBlockingQueue<Integer> pbq = new PriorityBlockingQueue<Integer>(capacityOfQueue); // Add element to PriorityBlockingQueue pbq.put(1); pbq.put(2); pbq.put(3); pbq.put(4); // find remaining Capacity of pbq // using remainingCapacity() method // The initial capacity was set to 7 // by passing as parameter in constructor // But this method will return Integer.MAX_VALUE int remainingCapacity = pbq.remainingCapacity(); // print result System.out.println("Queue: " + pbq); System.out.println("Remaining Capacity: " + remainingCapacity); } } Output: Queue: [1, 2, 3, 4] Remaining Capacity: 2147483647 Program 2: To demonstrate remainingCapacity() using String Java // Java Program Demonstrate remainingCapacity() // 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"); // find remaining Capacity of pbq // using remainingCapacity() method int remainingCapacity = pbq.remainingCapacity(); // print result System.out.println("Queue: " + pbq); System.out.println("Remaining Capacity: " + remainingCapacity); } } Output: Queue: [A Computer, Portal, Geeks, forGeeks] Remaining Capacity: 2147483647 Comment More infoAdvertise with us Next Article PriorityBlockingQueue remainingCapacity() 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 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 toString() method in Java The toString() method of PriorityBlockingQueue returns String representation of this PriorityBlockingQueue showing details of element contained by PriorityBlockingQueue. The string of PriorityBlockingQueue contains elements of PriorityBlockingQueue in the same order returned by its iterator, enclose 2 min read PriorityBlockingQueue remove() method in Java 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 re 2 min read PriorityBlockingQueue toArray() method in Java toArray() The toArray method of PriorityBlockingQueue is used to create an array having the same elements as that of this PriorityBlockingQueue, in proper sequence. Actually, this method copies all the element from the PriorityBlockingQueue to a new array. This method behaves as a bridge between arr 4 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 Like