Java ArrayBlockingQueue removeAll() Method7 Jan 2025 | 2 min read The removeAll() method of Java ArrayBlockingQueue class removes the elements of the ArrayBlockingQueue which are contained in the specified collection. Syntax:Parameters:Here, the parameter c is the collection containing elements to be removed from ArrayBlockingQueue. Specified By:The removeAll () method of ArrayBlockingQueue class is specified by: removeAll in interface Collection<E>. Return Value:The removeAll () method returns a Boolean value 'true' if the collection has changed as a result of the call, else it returns 'false'. Throws:It throws NullPointerException, if the specified collection does not support null elements or it contains one or more null elements. Example 1Output: Total no : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Even no : [2, 4, 6, 8, 10] Odd no : [1, 3, 5, 7, 9] Example 2Output: Total Patients = 6 Megha Reema Supriya Anoop Sonia Tejashvi Patients recovered and discharged : [Megha, Reema, Supriya, Anoop] Patients left in the hospital = 2 Sonia Tejashvi Example 3Output: Queue = [123, 56, 100] Exception in thread "main" java.lang.NullPointerException at java.util.Objects.requireNonNull(Objects.java:203) at java.util.AbstractCollection.removeAll(AbstractCollection.java:371) at com.javaTpoint.ArrayBlockingQueueRemoveAllExample3.main(ArrayBlockingQueueRemoveAllExample3.java:16) |
The take() method of Java ArrayBlockingQueue class retrieves and removes the first element of the ArrayBlockingQueue, waiting (if necessary) until an element becomes available. Syntax: public E take() throws InterrupedException Parameters: NA Specified By: The take() method of ArrayBlockingQueue class is specified by: take in interface BlockingQueue<E>. Return Value: The take() method returns the...
3 min read
The retainAll() method of Java ArrayBlockingQueue class retains only the elements of the ArrayBlockingQueue that are contained in the specified collection and removes rest of the elements. Syntax: public boolean retainAll(Collection<?> c) Parameters: Here, the parameter c is the collection containing elements to be retained in the ArrayBlockingQueue collection. Specified...
3 min read
The poll() method of ArrayBlockingQueue class retrieves the head of this queue awaiting till the specified time if essential for an element to be available, and also removes it. The method returns null if this queue is empty. Syntax: 1.public E poll() 2.public E poll(long timeout,TimeUnit unit)throws InterruptedException Parameters: NA timeout...
3 min read
The remainingCapacity() method of Java ArrayBlockingQueue class returns the capacity of the elements that this queue can accept without blocking. Syntax: public int remainingCapacity() Parameters: NA Specified By: The remainingCapacity () method of ArrayBlockingQueue class is specified by remainingCapacity in interface BlockingQueue. Return Value: The remainingCapacity () method returns the remaining capacity...
3 min read
The removeIf() method of Java ArrayBlockingQueue class removes the elements of the ArrayBlockingQueue that satisfies the given predicate filter. Syntax: public boolean removeIf(Predicate<? Super E> filter) Parameters: The parameter filter is a predicate which returns true for the elements to be removed. Specified By: The removeIf() method of ArrayBlockingQueue class is...
3 min read
The Spliterator() method of Java ArrayBlockingQueue class returns a Spliterator over the elements in this ArrayBlockingQueue. Syntax: public Spliterator<E> spliterator() Parameters: NA Specified By: The Spliterator () method of ArrayBlockingQueue class is specified by: Spliterator in interface Collection<E>. Spliterator in interface Iterable<E> Return Value: The Spliterator () method returns a Spliterator over the elements in...
4 min read
The offer() method of Java ArrayBlockingQueue class adds the defined element at the tail of this queue, only if the queue is not full or it waits till the specified wait time for space to get free, if the queue is full. Syntax: 1.public boolean offer(E e) 2.public...
4 min read
The add() method of ArrayBlockingQueue() appends the defined element at the tail end of the queue if the queue's capacity allows it. The method returns true on successful insertion and throws an IllegalStateException if queue doesn't has enough capacity. Syntax: public boolean add(E e) Parameters: e - This is the...
4 min read
The iterator() method of ArrayBlockingQueue class returns an iterator across the elements of this queue in a sequential manner. The elements returned will follow order from first (head) to last (tail). Syntax: public Iterator<E> iterator() Parameters: NA Specified By: The iterator() method of ArrayBlockingQueue class is specified by: iterator() method in interface Collection<E>. iterator()...
3 min read
The remove() method of ArrayBlockingQueue class removes the specified element from the queue, if that element is present in the queue. Syntax: public boolean remove(Object o) Parameters: The parameter 'o' is passed which is removed from the queue, if the element is present. Specified By: The remove () method of ArrayBlockingQueue...
3 min read
We request you to subscribe our newsletter for upcoming updates.
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