Java LinkedBlockingDeque clear() methodThe clear() method of LinkedBlockingDeque class automatically withdraws all the elements from this deque. The deque becomes empty, after calling this method. Syntax:Parameters:NA Specified By:The clear() method of class LinkedBlockingDeque is specified by clear() method in interface Collection<E>. Override:The clear() method of class LinkedBlockingDeque overrides the clear() method of class AbstractQueue<E>. Example 1Test it NowOutput: Deque : [23, 123, 12] After applying clear() method : Deque : [] Example 2Output: 1. Sugar 2. Salt 3. Potato 4. Rice Is Your shopping done.? true/false : Your queue is empty. Make a new list. Example 3Test it NowOutput: Exception in thread "main" java.lang.NullPointerException at java.util.concurrent.LinkedBlockingDeque.offerLast(LinkedBlockingDeque.java:357) at java.util.concurrent.LinkedBlockingDeque.addLast(LinkedBlockingDeque.java:334) at java.util.concurrent.LinkedBlockingDeque.add(LinkedBlockingDeque.java:633) at com.javaTpoint.LinkedBlockingDequeClearExample3.main(LinkedBlockingDequeClearExample3.java:7) Next TopicJava Linkedblockingdeque |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India