Java ArrayBlockingQueue drainTo() Method7 Jan 2025 | 2 min read The drainTo() method of ArrayBlockingQueue() class removes all the elements present in this queue and adds them to the provided collection. Syntax:Parameters:c - This is the collection to which elements are transferred. maxElements - This is the maximum number of elements to be transferred. Specified By:The drainTo() method of ArrayBlockingQueue class is specified by drainTo() method in interface BlockingQueue. Example 1Output: Elements int the queue = [0, 1, 2] Elements left in the queue :[] Elements drained in the list[0, 1, 2] Example 2Output: Elements int the queue = [0, 1, 2, 3] Elements left in the queue : [2, 3] Elements drained in the list : [0, 1] Next TopicJava-arrayblockingqueue-class |
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 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
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 removeIf() method of Java ArrayBlockingQueue class removes the elements of the ArrayBlockingQueue that satisfies the given predicate filter. Syntax: public boolean removeIf(Predicate<? Super E> filter) Parameters: The parameter filter is a predicate which returns true for the elements to be removed. Specified By: The removeIf() method of ArrayBlockingQueue class is...
3 min read
The add() method of ArrayBlockingQueue() appends the defined element at the tail end of the queue if the queue's capacity allows it. The method returns true on successful insertion and throws an IllegalStateException if queue doesn't has enough capacity. Syntax: public boolean add(E e) Parameters: e - This is the...
4 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 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 peek() method of Java ArrayBlockingQueue class retrieves the head of this queue, but doesn't remove it. The method returns null if this queue is empty. Syntax: public E peek() Parameters: NA Specified By: The peek() method of ArrayBlockingQueue class is specified by peek() method in interface Queue. Return Value: The peek() method...
3 min read
The iterator() method of ArrayBlockingQueue class returns an iterator across the elements of this queue in a sequential manner. The elements returned will follow order from first (head) to last (tail). Syntax: public Iterator<E> iterator() Parameters: NA Specified By: The iterator() method of ArrayBlockingQueue class is specified by: iterator() method in interface Collection<E>. iterator()...
3 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