LinkedBlockingDeque forEach() method in Java with Examples
The forEach() method of LinkedBlockingDeque performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.
Syntax:
public void forEach(Consumer<E> action)
Parameters: This method takes a parameter action which represents the action to be performed for each element.
Return Value: This method does not returns anything.
Exceptions: This method throws NullPointerException if the specified action is null.
Below program illustrates the forEach() function of LinkedBlockingDeque class:
Example:
// Java Program Demonstrate forEach() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws IllegalStateException { // create object of LinkedBlockingDeque LinkedBlockingDeque<Integer> LBD = new LinkedBlockingDeque<Integer>(); // Add numbers to end of LinkedBlockingDeque LBD.add(11); LBD.add(22); LBD.add(33); LBD.add(44); LBD.add(55); LBD.add(66); LBD.add(77); // print deque System.out.println("Linked Blocking Deque: " + LBD); System.out.println("Traversing this Deque: "); // Traverse this queue using forEach() method LBD.forEach((n) -> System.out.println(n)); } } |
Linked Blocking Deque: [11, 22, 33, 44, 55, 66, 77] Traversing this Deque: 11 22 33 44 55 66 77
Example: 2
// Java Program Demonstrate forEach() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws IllegalStateException { // create object of LinkedBlockingDeque LinkedBlockingDeque<String> LBD = new LinkedBlockingDeque<String>(); // Add elements to end of LinkedBlockingDeque LBD.add("GeeksforGeeks"); LBD.add("Gfg"); LBD.add("Geeks"); LBD.add("Computer"); LBD.add("Science"); LBD.add("Portal"); // print deque System.out.println("Linked Blocking Deque: " + LBD); System.out.println("Traversing this deque: "); // Traverse this deque using forEach() method LBD.forEach((n) -> System.out.println(n)); } } |
Linked Blocking Deque: [GeeksforGeeks, Gfg, Geeks, Computer, Science, Portal] Traversing this deque: GeeksforGeeks Gfg Geeks Computer Science Portal
Recommended Posts:
- LinkedBlockingDeque addAll() method in Java with Examples
- LinkedBlockingDeque removeAll() method in Java with Examples
- LinkedBlockingDeque retainAll() method in Java with Examples
- LinkedBlockingDeque removeIf() method in Java with Examples
- Stream forEach() method in Java with examples
- Iterable forEach() method in Java with Examples
- LinkedTransferQueue forEach() method in Java with Examples
- HashTable forEach() method in Java with Examples
- CopyOnWriteArraySet forEach() method in Java with Examples
- CopyOnWriteArrayList forEach() method in Java with Examples
- Properties forEach(BiConsumer) method in Java with Examples
- LinkedBlockingDeque in Java with Examples
- LinkedBlockingDeque pop() method in Java
- LinkedBlockingDeque contains() method in Java
- LinkedBlockingDeque put() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



