DelayQueue remove() method in Java Last Updated : 23 Dec, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The remove() method of DelayQueue class in Java is used to remove a single instance of the given object say obj from this DelayQueue if it is present. It returns true if the given element is removed successfully otherwise it returns false. Syntax: public boolean remove(Object obj) Parameters: This method takes a single object obj as parameter which is to be removed from this DealyQueue. Return Value: It returns a boolean value which is true if the element has been successfully deleted otherwise it returns false. Below program illustrate the remove() method of DelayQueue in Java: Java // Java Program to illustrate the remove method // of DelayQueue class import java.util.concurrent.DelayQueue; import java.util.concurrent.Delayed; import java.util.concurrent.TimeUnit; public class GFG { public static void main(String args[]) { // Create a DelayQueue instance DelayQueue<Delayed> queue = new DelayQueue<Delayed>(); // Create an object of type Delayed Delayed ob = new Delayed() { public long getDelay(TimeUnit unit) { return 24; // some value is returned } public int compareTo(Delayed o) { if (o.getDelay(TimeUnit.DAYS) > this.getDelay(TimeUnit.DAYS)) return 1; else if (o.getDelay(TimeUnit.DAYS) == this.getDelay(TimeUnit.DAYS)) return 0; return -1; } }; // Add the object to DelayQueue queue.add(ob); // Print initial size of Queue System.out.println("Initial Size : " + queue.size()); // Remove the object ob from // this DelayQueue queue.remove(ob); // Print the final size of the DelayQueue System.out.println("Size after removing : " + queue.size()); } } Output: Initial Size : 1 Size after removing : 0 Comment More infoAdvertise with us Next Article DelayQueue remove() method in Java P psil123 Follow Improve Article Tags : Java Java - util package java-DelayQueue Practice Tags : Java Similar Reads ArrayDeque remove() Method in Java The Java.util.ArrayDeque.remove() method is used to remove the element present at the head of the Deque. Syntax: Array_Deque.remove() Parameters: The method does not take any parameters. Return Value: This method returns the element present at the head of the Deque. Exceptions: The method throws NoS 3 min read ArrayBlockingQueue remove() method in Java ArrayBlockingQueue is bounded, blocking queue that stores the elements internally backed by an array. ArrayBlockingQueue class is a member of the Java Collections Framework. Bounded means it will have a fixed size, you can not store number the elements more than the capacity of the queue. The queue 3 min read ArrayDeque removeAll() method in Java The removeAll() method of ArrayDeque is used to remove all the elements which is common in both ArrayDeque and the collection passed as parameter. This method first collect all the elements of Collection and then starts removing the elements from ArrayDeque which are same as elements of Collection.A 4 min read DelayQueue clear() method in Java 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. Syntax: public void clear() 2 min read HashSet remove() Method in Java The HashSet remove() method in Java is used to remove a specific element from the set if it is present.Note: HashSet and the remove() were introduced in JDK 1.2 as part of the Collections Framework and are not available in earlier versions of Java (JDK 1.0 and JDK 1.1).Example 1: Here, the remove() 2 min read Like