Java Collection Tutorial - Java ArrayBlockingQueue(int capacity, boolean fair, Collection <? extends E > c) Constructor








Syntax

ArrayBlockingQueue(int capacity, boolean fair, Collection <? extends E > c) constructor from ArrayBlockingQueue has the following syntax.

public ArrayBlockingQueue(int capacity,     boolean fair,     Collection <? extends E > c)

Example

In the following code shows how to use ArrayBlockingQueue.ArrayBlockingQueue(int capacity, boolean fair, Collection <? extends E > c) constructor.

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
//from   w ww.j  a  va  2 s .  c o m
public class Main {
  public static void main(String[] argv) throws Exception {
    List<Integer> list = Arrays.asList(new Integer[]{0,1,2,3});
    
    
    int capacity = 100;
    ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity,true,list);
    queue.put(0);
    queue.put(1);
    queue.put(2);
    System.out.println(queue);
    System.out.println(list);
  }
}

The code above generates the following result.