The clear() method of DelayQueue in Java is used to remove all of the elements in the current DelayQueue object. The queue will be empty after this call is returned. The elements in the queue whose Delay does not have an Expiry are automatically discarded from the Queue.
public void clear()
Parameters: This method does not takes any parameter.
Return Value: This method does not returns any value.
Below program illustrate the above method:
Is queue empty() : false Is queue empty after calling clear() : true
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.