LinkedBlockingDeque forEach() method in Java with Examples Last Updated : 19 Mar, 2019 Comments Improve Suggest changes Like Article Like Report 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 // 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)); } } Output: Linked Blocking Deque: [11, 22, 33, 44, 55, 66, 77] Traversing this Deque: 11 22 33 44 55 66 77 Example: 2 Java // 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)); } } Output: Linked Blocking Deque: [GeeksforGeeks, Gfg, Geeks, Computer, Science, Portal] Traversing this deque: GeeksforGeeks Gfg Geeks Computer Science Portal Reference: https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/LinkedBlockingDeque.html#forEach-java.util.function.Consumer- Comment More infoAdvertise with us Next Article LinkedBlockingDeque forEach() method in Java with Examples P ProgrammerAnvesh Follow Improve Article Tags : Java Java - util package Java-Functions Java-LinkedBlockingDeque Practice Tags : Java Similar Reads LinkedTransferQueue forEach() method in Java with Examples The forEach() method of Java.util.concurrent.LinkedTransferQueue is an in-built function in Java which is used to traverse each element in this queue. Syntax: public void forEach(Consumer<E> action) Parameters: This method takes a parameter action which represents the action to be performed fo 2 min read LinkedBlockingDeque addAll() method in Java with Examples The addAll() method of LinkedBlockingDeque appends all of the elements of the specified collection to the end of this deque.Syntax: public void addAll(Collection<E> c) Parameters: This method accepts a mandatory parameter c which is the collection to be inserted in the end of the LinkedBlockin 2 min read LinkedBlockingDeque in Java with Examples The LinkedBlockingDeque class in Java is a part of the Java Collection Framework. It was introduced in JDK 1.6 and it belongs to java.util.concurrent package. It is a Deque(Doubly Ended Queue) which blocks a thread if that thread tries to take elements out of it while the Deque is empty. It implemen 14 min read LinkedBlockingDeque toArray() method in Java with Example toArray() The Java.util.concurrent.LinkedBlockingDeque.toArray() method returns an array containing all the elements in the deque in proper sequence i.e. from first to last. The returned array will be safe as a new array is created (hence new memory is allocated). Thus the caller is free to modify t 3 min read LinkedBlockingDeque drainTo() method in Java with Example The drainTo(Collection col) method of LinkedBlockingDeque removes all available elements from this LinkedBlockingDeque and adds them to the given collection passed as a parameter. drainTo(Collection<E> col) The drainTo(Collection<E> col) method of LinkedBlockingDeque removes all of the e 7 min read Like