Java Collection Tutorial - Java BlockingDeque.iterator()








Syntax

BlockingDeque.iterator() has the following syntax.

Iterator < E > iterator()

Example

In the following code shows how to use BlockingDeque.iterator() method.

/* ww w  .j  av  a 2 s  .  c  o  m*/
import java.util.Iterator;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class Main {
  public static void main(String[] argv) throws Exception {
    int capacity = 10;
    BlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);

    for (int i = 0; i < 10; i++) {
      queue.add(i);
    }
    Iterator<Integer> it = queue.iterator();
    while(it.hasNext()){
      System.out.println(it.next());
    }
  }
}

The code above generates the following result.