Java ArrayBlockingQueue forEach() Method7 Jan 2025 | 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:Parameters:action - This is the action to be performed for every element. Specified By:The forEach() method of ArrayBlockingQueue class is specified by forEach() method in interface Iterable<E>. Throws:The forEach() method throws NullPointerException, if the defined action represents null. Example 1Output: [Reema, Rahul, Rita, Ramesh] Printing the queue with the help of foreach loop: Reema Rahul Rita Ramesh Example 2Output: 1.Roll No. = 15cs1029 College = MVN University Name = Reema 2.Roll No. = 15cs1010 College = MVN University Name = Geetanjali 3.Roll No. = 17cs1029 College = MR University Name = Vineet 4.Roll No. = 15cs1011 College = MVN University Name = Himanshu Example 3Output: 1 Lower case = aman Upper case = AMAN 2 Lower case = bhavika Upper case = BHAVIKA Example 4Output: 71018 8000 1178 1190 Max number = 71018 Min number = 1178 Next TopicJava-arrayblockingqueue-iterator-method |
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 drainTo() method of ArrayBlockingQueue() class removes all the elements present in this queue and adds them to the provided collection. Syntax: public int drainTo(Collection<? super E> c) public int drainTo(Collection<? super E> c, int maxElements) Parameters: c - This is the collection to which elements are transferred. maxElements - This...
2 min read
The remainingCapacity() method of Java ArrayBlockingQueue class returns the capacity of the elements that this queue can accept without blocking. Syntax: public int remainingCapacity() 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...
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
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 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 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 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
The toString() method of Java ArrayBlockingQueue returns a string representation of this collection. Syntax: public String toString() Parameters: NA Overrides toString in class AbstractionCollection<E> Return Value: The toString() method returns a string representation of this collection. Example 1 import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; public class ArrayBlockingQueueToStringExample1 { public static void main(String[] args) { ...
2 min read
The toArray() method of Java ArrayBlockingQueue returns an array containing all the elements of the ArrayBlockingQueue, in proper sequence. The syntax of toArray() returns an array where the runtime of the returned array is that of the specified array, and if the queue fits in...
6 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