Online Java Compiler By
JavaTpoint.com
import java.util.ArrayList; import java.util.List; import java.util.concurrent.LinkedBlockingDeque; public class LinkedBlockingDequeDrainToExample2 { public static void main(String[] args) { List
list = new ArrayList
(); int capacity = 100; LinkedBlockingDeque
deque = new LinkedBlockingDeque
(capacity); for (int i=0;i<11;i++) { deque.add(i); } System.out.println("Elements int the queue = "+deque); /*drainTo() method removes at most the given number of available elements from this queue and adds them to the list.*/ deque.drainTo(list,5); System.out.println("Elements left in the queue :"+deque); System.out.println("Elements drained in the list"+list); } }
Output