VOOZH about

URL: https://www.geeksforgeeks.org/java/blockingdeque-removefirstoccurrence-method-in-java-with-examples/

⇱ BlockingDeque removeFirstOccurrence() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

BlockingDeque removeFirstOccurrence() method in Java with Examples

Last Updated : 19 Jul, 2021

The removeFirstOccurrence() method of BlockingDeque removes the first occurrence of the specified element from this deque. If the deque does not contain the element, it remains unchanged. It returns true if this deque contained the specified element, else it returns false. 

Syntax: 

public boolean removeFirstOccurrence(Object o)

Parameters: This method accepts a mandatory parameter o which specifies the element to be removed from the Deque container. 

Returns: This method returns true if the element is present and removed from the Deque container, else it returns false

Note: The removeFirstOccurrence() method of BlockingDeque has been inherited from the LinkedBlockingDeque class in Java.
Below programs illustrate removeFirstOccurrence() method of BlockingDeque:

Program 1: When element is present 


Output
Blocking Deque: [15, 20, 20, 15]
First occurrence of 15 removed
Blocking Deque: [20, 20, 15]

Program 2: When element is not present


Output: 
Blocking Deque: [15, 20, 20, 15]
10 not present and not removed
Blocking Deque: [15, 20, 20, 15]

 

Reference: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/BlockingDeque.html#removeFirstOccurrence(java.lang.Object)
 

Comment