Java ArrayBlockingQueue .drainTo (Collection <? super E > c, int maxElements)
Syntax
ArrayBlockingQueue.drainTo(Collection <? super E > c, int maxElements) has the following syntax.
public int drainTo(Collection <? super E > c, int maxElements)
Example
In the following code shows how to use ArrayBlockingQueue.drainTo(Collection <? super E > c, int maxElements) method.
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
//from w w w.ja v a2s . com
public class Main {
public static void main(String[] argv) throws Exception {
List<Integer> list = new ArrayList<Integer>();
int capacity = 100;
ArrayBlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(capacity);
queue.put(0);
queue.put(1);
queue.put(2);
queue.drainTo(list,3);
System.out.println(queue);
System.out.println(list);
}
}
The code above generates the following result.