BlockingDeque iterator() method in Java with examples Last Updated : 01 Oct, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The iterator() method of BlockingDeque returns an iterator over the elements in this deque in a proper sequence. The elements will be returned in order from first (head) to last (tail). The returned iterator is a "weakly consistent" iterator. Syntax: public Iterator iterator() Parameters: This method does not accept any parameter. Returns: This method returns an iterator over the elements in this deque in a proper sequence. Note: The iterator() method of BlockingDeque has been inherited from the LinkedBlockingDeque class in Java. Below programs illustrate iterator() method of BlockingDeque: Program 1: Java // Java Program Demonstrate iterator() // method of BlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.BlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) { // create object of BlockingDeque BlockingDeque<Integer> BD = new LinkedBlockingDeque<Integer>(); // Add numbers to front of BlockingDeque BD.addFirst(7855642); BD.addFirst(35658786); BD.addFirst(5278367); BD.addFirst(74381793); // Call iterator() method of BlockingDeque Iterator iteratorVals = BD.iterator(); // Print elements of iterator // created from PriorityBlockingQueue System.out.println("The iterator values" + " of BlockingDeque are:"); // prints the elements using an iterator while (iteratorVals.hasNext()) { System.out.println(iteratorVals.next()); } } } Output: The iterator values of BlockingDeque are: 74381793 5278367 35658786 7855642 Program 2: Java // Java Program Demonstrate iterator() // method of BlockingDeque // when list is of strings import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.BlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) { // create object of BlockingDeque BlockingDeque<String> BD = new LinkedBlockingDeque<String>(); // Add numbers to front of BlockingDeque BD.add("Geeks"); BD.add("forGeeks"); BD.add("A"); BD.add("Computer"); BD.add("Portal"); // Call iterator() method of BlockingDeque Iterator iteratorVals = BD.iterator(); // Print elements of iterator // created from BlockingQueue System.out.println("The iterator values" + " of LinkedBlockingDeque are:"); // prints the elements using an iterator while (iteratorVals.hasNext()) { System.out.println(iteratorVals.next()); } } } Output: The iterator values of BlockingDeque are: Geeks forGeeks A Computer Portal Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/BlockingDeque.html#iterator() Comment More infoAdvertise with us Next Article ConcurrentLinkedDeque iterator() method in Java with Example G gopaldave Follow Improve Article Tags : Java Java-Collections Java-Functions java-interfaces Practice Tags : JavaJava-Collections Similar Reads DelayQueue iterator() method in Java with Examples The iterator() method of DelayQueue is used to return an iterator over all the elements in the DelayQueue. These elements can be expired or unexpired.Syntax: public Iterator iterator () Parameters: This method does not accept any parameter.Returns: This method returns an iterator over elements in th 2 min read BlockingDeque take() method in Java with Examples The take() method of BlockingDeque returns and removes the head of the Deque container from it. The method throws an InterruptedException if it is interrupted while waiting. Syntax: public E take() Returns: This method returns the head of the Deque container. Exception: The function throws a Interru 2 min read ConcurrentLinkedDeque iterator() method in Java with Example The Java.util.concurrent.ConcurrentLinkedDeque.iterator() method is used to return an iterator of the same elements as that of the ConcurrentLinkedDeque. The elements are returned in random order from what was present in the deque. Syntax: Iterator iterate_value = ConcurrentLinkedDeque.iterator(); P 2 min read BlockingDeque element() method in java with examples The element() method of BlockingDeque returns the element at the front the container. It does not delete the element in the container. This method returns the head of the queue represented by this deque. Syntax: public void element() Parameters: This method does not accept any parameter. Returns: Th 2 min read ArrayList iterator() method in Java with Examples The iterator() method of ArrayList class in Java Collection Framework is used to get an iterator over the elements in this list in proper sequence. The returned iterator is fail-fast. Syntax: Iterator iterator() Parameter: This method do not accept any parameter. Return Value: This method returns an 2 min read BlockingDeque takeFirst() method in Java with Examples The takeFirst() method of BlockingDeque returns and removes the first element of the Deque container from it, waiting if necessary until an element becomes available.. The method throws an InterruptedException if it is interrupted while waiting. Syntax: public E takeFirst() Returns: This method retu 2 min read Like