Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
LinkedBlockingDeque removeFirstOccurrence() method in Java
Next article icon

LinkedBlockingDeque removeFirstOccurrence() method in Java

Last Updated : 04 Aug, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

The removeFirstOccurrence() method of LinkedBlockingDeque 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. 
Below programs illustrate removeFirstOccurrence() method of LinkedBlockingDeque:
Program 1: When element is present
 

Java
// Java Program to demonstrate removeFirstOccurrence() // method of LinkedBlockingDeque  import java.util.concurrent.LinkedBlockingDeque; import java.util.*;  public class GFG {     public static void main(String[] args)         throws InterruptedException     {          // create object of LinkedBlockingDeque         LinkedBlockingDeque<Integer> LBD             = new LinkedBlockingDeque<Integer>();          // Add numbers to end of LinkedBlockingDeque         LBD.add(15);         LBD.add(20);         LBD.add(20);         LBD.add(15);          // print Dequeue         System.out.println("Linked Blocking Deque: " + LBD);          if (LBD.removeFirstOccurrence(15))             System.out.println("First occurrence of 15 removed");         else             System.out.println("15 not present and not removed");          // prints the Deque after removal         System.out.println("Linked Blocking Deque: " + LBD);     } } 

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

Program 2: When element is not present
 

Java
// Java Program to demonstrate removeFirstOccurrence() // method of LinkedBlockingDeque  import java.util.concurrent.LinkedBlockingDeque; import java.util.*;  public class GFG {     public static void main(String[] args)         throws InterruptedException     {          // create object of LinkedBlockingDeque         LinkedBlockingDeque<Integer> LBD             = new LinkedBlockingDeque<Integer>();          // Add numbers to end of LinkedBlockingDeque         LBD.add(15);         LBD.add(20);         LBD.add(20);         LBD.add(15);          // print Dequeue         System.out.println("Linked Blocking Deque: " + LBD);          if (LBD.removeFirstOccurrence(10))             System.out.println("First occurrence of 10 removed");         else             System.out.println("10 not present and not removed");          // prints the Deque after removal         System.out.println("Linked Blocking Deque: " + LBD);     } } 

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

 

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingDeque.html#removeFirstOccurrence-java.lang.Object-
 


Next Article
LinkedBlockingDeque removeFirstOccurrence() method in Java

G

gopaldave
Improve
Article Tags :
  • Misc
  • Java
  • Java - util package
  • Java-Functions
  • Java-LinkedBlockingDeque
Practice Tags :
  • Java
  • Misc

Similar Reads

    LinkedBlockingDeque contains() method in Java
    The contains(Object o) method of LinkedBlockingDeque checks if the passed element in the parameter exists in the container or not. It returns true if the element exists in the container else it returns a false value. Syntax: public boolean contains(Object o) Parameters: This method accepts a mandato
    2 min read
    LinkedBlockingDeque offerLast() method in Java
    The offerLast(E e) method of LinkedBlockingDeque inserts the element passed in the parameter at the end of the Deque container. If the container's capacity has exceeded, then it does not returns an exception as in case of add() and addLast() function. Syntax: public boolean offerLast(E e) Parameters
    2 min read
    LinkedBlockingDeque pollLast() method in Java
    The pollLast() method of LinkedBlockingDeque returns the last element in the Deque container, and deletes it. It returns null if the container is empty. Syntax: public E pollLast() Parameters: This method does not accept any parameters. Returns: This method returns last element in the Deque containe
    2 min read
    LinkedBlockingDeque pollFirst() method in Java
    The pollFirst() method of LinkedBlockingDeque returns the front element in the Deque container, and deletes it. It returns null if the container is empty. Syntax: public E pollFirst() Parameters: This method does not accept any parameters. Returns: This method returns front element in the Deque cont
    2 min read
    LinkedBlockingDeque addLast() method in Java
    The addLast(E e) method of LinkedBlockingDeque inserts the element passed in the parameter to the end of the Deque if there is space. If the LinkedBlockingDeque is capacity restricted and no space is left for insertion, it returns an IllegalStateException. Syntax: public void addLast(E e) Parameters
    2 min read
    LinkedBlockingDeque removeLast() method in Java
    The removeLast() method of LinkedBlockingDeque returns and removes the element at tail of the Deque container. The method throws an NoSuchElementException if the Deque container is empty. Syntax: public E removeLast() Parameters: This method does not accepts any parameter. Returns: This method retur
    2 min read
    LinkedBlockingDeque remove() method in Java
    The remove() method of LinkedBlockingDeque removes the head of the Deque container. The method throws a NoSuchElementException if the Deque container is empty. Syntax: public E remove() Parameters: This method does not accepts any parameter. Returns: This method does not returns anything. Exception:
    2 min read
    LinkedBlockingDeque put() method in Java
    The put(E e) method of LinkedBlockingDeque inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque). If the Deque is capacity restricted, then it will wait for the space to become available. Syntax: public void put(E e) Parameters: This metho
    2 min read
    LinkedBlockingDeque putFirst() method in Java
    The putFirst(E e) method of LinkedBlockingDeque inserts the specified element at the front of the queue represented by this deque. If the Deque is capacity restricted, then it will wait for the space to become available. Syntax: public void putFirst(E e) Parameters: This method accepts a mandatory p
    2 min read
    LinkedBlockingDeque removeFirst() method in Java
    The removeFirst() method of LinkedBlockingDeque returns and removes the first element of the Deque container from it. The method throws an NoSuchElementException if the Deque container is empty. Syntax: public E removeFirst() Returns: This method returns the head of the Deque container, which is the
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences