Java ArrayBlockingQueue remainingCapacity() Method7 Jan 2025 | 2 min read The remainingCapacity() method of Java ArrayBlockingQueue class returns the capacity of the elements that this queue can accept without blocking. Syntax:Parameters:NA Specified By:The remainingCapacity () method of ArrayBlockingQueue class is specified by remainingCapacity in interface BlockingQueue Return Value:The remainingCapacity () method returns the remaining capacity of the queue. Example 1Output: Queue : [1, 2, 3, 4, 5, 6] Remaining capacity of the queue = 4 Example 2Output: Register your name quickly in JavaTpoint. As only 7 seats are left Example 3Output: Enter capacity : 5 Remaining capacity : 5 Element : 56 Remaining capacity : 4 Element : 78 Remaining capacity : 3 Element : 55 Remaining capacity : 2 Element : 9 Remaining capacity : 1 Element : 76 Queue = [56, 78, 55, 9, 76] Next TopicJava-arrayblockingqueue-remove-method |
The size() method of Java ArrayBlockingQueue class returns the total number of elements in the ArrayBlockingQueue. Syntax: public int size() Parameters: NA Specified By: The size() method of ArrayBlockingQueue class is specified by: Size in interface Collection<E>. Size in class AbstractCollection<E> Return Value: The size() method returns the total number of elements in this queue. Example...
3 min read
The poll() method of ArrayBlockingQueue class retrieves the head of this queue awaiting till the specified time if essential for an element to be available, and also removes it. The method returns null if this queue is empty. Syntax: 1.public E poll() 2.public E poll(long timeout,TimeUnit unit)throws InterruptedException Parameters: NA timeout...
3 min read
The retainAll() method of Java ArrayBlockingQueue class retains only the elements of the ArrayBlockingQueue that are contained in the specified collection and removes rest of the elements. Syntax: public boolean retainAll(Collection<?> c) Parameters: Here, the parameter c is the collection containing elements to be retained in the ArrayBlockingQueue collection. Specified...
3 min read
The contains() method of Java ArrayBlockingQueue() class returns true if the defined element is present in this queue. Syntax: public boolean contains(Object o) Parameters: o - This is the object that is to be checked for occurrence in this queue. Specified By: The contains() method of ArrayBlockingQueue class is specified by: contains()...
2 min read
The removeAll() method of Java ArrayBlockingQueue class removes the elements of the ArrayBlockingQueue which are contained in the specified collection. Syntax: public boolean removeAll(Collection<?> c) Parameters: Here, the parameter c is the collection containing elements to be removed from ArrayBlockingQueue. Specified By: The removeAll () method of ArrayBlockingQueue...
4 min read
The remove() method of ArrayBlockingQueue class removes the specified element from the queue, if that element is present in the queue. Syntax: public boolean remove(Object o) Parameters: The parameter 'o' is passed which is removed from the queue, if the element is present. Specified By: The remove () method of ArrayBlockingQueue...
3 min read
The offer() method of Java ArrayBlockingQueue class adds the defined element at the tail of this queue, only if the queue is not full or it waits till the specified wait time for space to get free, if the queue is full. Syntax: 1.public boolean offer(E e) 2.public...
4 min read
The put() method of ArrayBlockingQueue adds the defined element at the tail of this queue. It waits till the space becomes available if queue is full. Syntax: public void put(E e) throws InterruptedException Parameters: e - This is the element to be added. Specified By: The put() method of ArrayBlockingQueue class...
3 min read
ArrayBlockingQueue is a bounded blocking queue which orders the element in FIFO(first-in-first-out). In this queue, new elements are inserted at the tail of this queue and the elements are retrieved from the head of this queue. ArrayBlockingQueue class implements all the optional methods of the Collection...
3 min read
The forEach() method of Java ArrayBlockingQueue class executes the specified action for each element of Iterable till all the elements are processed or the action throws an exception. Syntax: public void forEach(Consumer<? super E> action) Parameters: action - This is the action to be performed for every element. Specified By: The...
4 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India