package devmanuals.com; import java.util.concurrent.BlockingDeque; import java.util.concurrent.LinkedBlockingDeque; class Peek implements Runnable { BlockingDeque bdq; public Peek(BlockingDeque bdq) { this.bdq = bdq; } public void run() { System.out.println("Elements of deque are : "); int i; boolean bol = false; for (i = 0; i < 5; i++) { bdq.add(i); } System.out.println(bdq); System.out.println("Size of deque = " + bdq.size()); try { Thread.sleep(500); System.out.println("The first element of deque is = "); Thread.sleep(1000); Integer obj = bdq.peek(); System.out.println(obj); bol = bdq.contains(obj); System.out.println("The element " + obj + " is still present into the deque? "); Thread.sleep(1000); System.out.println(bol); System.out.println("Now removed all the elements from the deque"); bdq.clear(); System.out.println("Therefore the deque is "+bdq+" empty"); System.out.println("Therefore first element of deque is : "); Integer obj1= bdq.peek();//call of this method will return 'null' Thread.sleep(2000); System.out.println(obj1); } catch (InterruptedException e) { e.printStackTrace(); } } } public class BdqPeek { public static void main(String[] args) { BlockingDeque bdq = new LinkedBlockingDeque(); Runnable a = new Peek(bdq); new Thread(a).start(); } }