Java ArrayBlockingQueue .toArray (T[] a)

Syntax

ArrayBlockingQueue.toArray(T[] a) has the following syntax.

public <T> T[] toArray(T[] a)

Example

In the following code shows how to use ArrayBlockingQueue.toArray(T[] a) method.


import java.util.Arrays;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
/*  w w  w .j av a 2s .c  o m*/
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);
    }
    
    System.out.println(Arrays.toString(queue.toArray(new Integer[queue.size()])));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.util.concurrent »




ArrayBlockingQueue
BlockingDeque
CountDownLatch
CyclicBarrier
TimeUnit