The add(E ele) method of DelayQueue class in Java is used to insert the given element into the delay queue and returns true if the element has been successfully inserted. Here, E refers to the type of elements maintained by this DelayQueue collection.
public boolean add(E ele)
Parameters: This method takes only one parameter ele. It refers to the element which will be inserted into the delay queue.
Return Value: It returns a boolean value which is true if the element has been added successfully otherwise it returns flase.
- NullPointerException: This method throws a NullPointerException if a NULL is tried to inserted in this DelayQueue.
Below programs illustrate the add() method of DelayQueue class:
Size of the queue : 1
Program 2: Program to demonstrate the NullPointerException.
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.