Java ArrayBlockingQueue forEach() Method

7 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 1

Output:

 [Reema, Rahul, Rita, Ramesh] Printing the queue with the help of foreach loop: Reema Rahul Rita Ramesh 

Example 2

Output:

 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 3

Output:

 1 Lower case = aman Upper case = AMAN 2 Lower case = bhavika Upper case = BHAVIKA 

Example 4

Output:

 71018 8000 1178 1190 Max number = 71018 Min number = 1178