DelayQueue remainingCapacity() method in Java with Examples Last Updated : 09 Jul, 2021 Comments Improve Suggest changes Like Article Like Report The remainingCapacity() method of DelayQueue always returns Integer.MAX_VALUE because a DelayQueue is not capacity constrained. That means, irrespective of the size of the DelayQueue it returns same result, i.e. Integer.MAX_VALUE. Syntax: public int remainingCapacity () Return Value: The function returns Integer.MAX_VALUE.Exception: No exceptions are present. Below programs illustrate the DelayQueue.remainingCapacity() method: Program: Java // Java Program Demonstrate DelayQueue remainingCapacity() method import java.util.concurrent.*; import java.util.*; // The DelayObject for DelayQueue // It must implement Delayed and // its getDelay() and compareTo() method class DelayObject implements Delayed { private String name; private long time; // Constructor of DelayObject public DelayObject(String name, long delayTime) { this.name = name; this.time = System.currentTimeMillis() + delayTime; } // Implementing getDelay() method of Delayed @Override public long getDelay(TimeUnit unit) { long diff = time - System.currentTimeMillis(); return unit.convert(diff, TimeUnit.MILLISECONDS); } // Implementing compareTo() method of Delayed @Override public int compareTo(Delayed obj) { if (this.time < ((DelayObject)obj).time) { return -1; } if (this.time > ((DelayObject)obj).time) { return 1; } return 0; } // Implementing toString() method of Delayed @Override public String toString() { return "\n{" + " " + name + ", time=" + time + "}"; } } // Driver Class public class GFG { public static void main(String[] args) throws InterruptedException { // create object of DelayQueue // using DelayQueue() constructor BlockingQueue<DelayObject> DQ = new DelayQueue<DelayObject>(); // Add numbers to end of DelayQueue // using add() method DQ.add(new DelayObject("A", 1)); DQ.add(new DelayObject("B", 2)); // print the size of DelayQueue System.out.println("Size of the DelayQueue: " + DQ.size()); // remainingCapacity() method always returns Integer.MAX_VALUE System.out.println("DelayQueue Remaining Capacity:" + DQ.remainingCapacity()); // poll() method for removing head of the DelayQueue DQ.poll(); // print the size of DelayQueue System.out.println("Size of the DelayQueue: " + DQ.size()); // remainingCapacity() method always returns Integer.MAX_VALUE System.out.println("DelayQueue Remaining Capacity:" + DQ.remainingCapacity()); // poll() method for removing head of the DelayQueue DQ.poll(); // print the size of DelayQueue System.out.println("Size of the DelayQueue: " + DQ.size()); // remainingCapacity() method always returns Integer.MAX_VALUE System.out.println("DelayQueue Remaining Capacity:" + DQ.remainingCapacity()); } } Output: Size of the DelayQueue: 2 DelayQueue Remaining Capacity:2147483647 Size of the DelayQueue: 1 DelayQueue Remaining Capacity:2147483647 Size of the DelayQueue: 0 DelayQueue Remaining Capacity:2147483647 Comment More infoAdvertise with us Next Article DelayQueue remainingCapacity() method in Java with Examples P ProgrammerAnvesh Follow Improve Article Tags : Java Java-Collections Java-Functions java-DelayQueue Practice Tags : JavaJava-Collections Similar Reads BlockingQueue remainingCapacity() method in Java with examples The remainingCapacity() method of BlockingQueue returns the number of more elements that can be added to BlockingQueue without blocking. The Capacity returned arises in three cases: If remaining Capacity is Zero, then no more elements can be added to the BlockingQueue. If remaining Capacity of Block 3 min read DelayQueue put() method in Java with Examples The put(E ele) method of DelayQueue class in Java is used to inserts a given element into the delay queue container. Hetre, E is the type of element maintained by this DelayQueue container. Syntax: public void put(E ele) Parameters: This method accepts only one parameter ele. It is the element which 2 min read DelayQueue toArray() method in Java with Examples The toArray() method of DelayQueue is used to return an array containing all the elements in DelayQueue. There elements are not in any specific order in the array.Syntax: public Object[] toArray () or public T[] toArray (T[] a) Parameters: This method either accepts no parameters or it takes an arra 4 min read DelayQueue take() method in Java with Examples The take() method of DelayQueue is used to retrieve head of the DelayQueue and also removes it. Thus, the size of the DelayQueue is reduced. This function waits if an element with expired delay is available on this queue. Syntax: public E take () Parameters: This method accepts no parameters.Return 2 min read DelayQueue poll() method in Java with Examples The poll() method of DelayQueue is used to retrieve head of the DelayQueue. This method also removes the head from the DelayQueue. Thus when poll method is called, DelayQueue size is reduced by one.Syntax: public E poll () Parameters: This method does not accept any parameter.Returns: This method re 3 min read Like