LinkedBlockingQueue remainingCapacity() method in Java
The remainingCapacity() method of LinkedBlockingQueue returns the number of more elements that can be added to LinkedBlockingQueue without blocking.
Thr Capacity returned arises three cases:
- If remaining Capacity is Zero, then no more elements can be added to the LinkedBlockingQueue.
- If remaining Capacity of LinkedBlockingQueue is equal to the size of the Queue, then no element can be removed from the queue because in such situation queue is empty.
- In any other case, Capacity is always equal to a difference between the initial capacity of this LinkedBlockinQueue and the current size of this LinkedBlockingQueue.
public int remainingCapacity()
Return Value: This method returns the remaining capacity of the LinkedBlockingQueue.
Below programs illustrates remainingCapacity() method of LinkedBlockingQueue class:
Program 1: Returning the remaining Capacity of the LinkedBlockingQueue using remainingCapacity() method where LinkedBlockingQueue contains list of names.
Queue is [John, Tom, Clark, Kat] Remaining Capacity of Queue is 3
Program 2: Finding Remaining Capacity of LinkedBlockingQueue which contains list of Employees.
Adding employee is success true Remaining Capacity of list :4 Adding employee is success true Remaining Capacity of list :3 Adding employee is success true Remaining Capacity of list :2 Adding employee is success true Remaining Capacity of list :1 Adding employee is success true Remaining Capacity of list :0
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.