VOOZH about

URL: https://www.geeksforgeeks.org/java/blockingqueue-remainingcapacity-method-in-java-with-examples/

⇱ BlockingQueue remainingCapacity() method in Java with examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

BlockingQueue remainingCapacity() method in Java with examples

Last Updated : 12 Jul, 2025
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 BlockingQueue 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 BlockingQueue and the current size of this BlockingQueue.
Syntax:
public int remainingCapacity()
Return Value: This method returns the remaining capacity of the BlockingQueue. Note: The remainingCapacity() method of BlockingQueue has been inherited from the Queue class in Java. Below programs illustrates remainingCapacity() method of BlockingQueue class: Program 1:
Output:
Queue is [John, Tom, Clark, Kat]
Remaining Capacity of Queue is 3
Program 2:
Output:
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
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/BlockingQueue.html#remainingCapacity()
Comment