VOOZH about

URL: https://www.geeksforgeeks.org/java/linkedlist-removefirstoccurrence-method-in-java/

⇱ LinkedList removeFirstOccurrence() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

LinkedList removeFirstOccurrence() Method in Java

Last Updated : 11 Jul, 2025

In Java, the removeFirstOccurrence() method of the LinkedList class is used to remove the first occurrence of the specified element from the list. If there is no occurrence of the specified element the list remains unchanged.

Example 1: Here, we use the removeFirstOccurence() method to remove the first occurrence of the specified element in a LinkedList of Strings.


Output
[A, B, C, B, D]
First Occurence of B is removed: true
M is present in the Linked List: false
[A, C, B, D]

Syntax of LinkedList removeFirstOccurrence() Method

public boolean removeFirstOccurrence(Object o)

Return Type:

  • This method is going to return true, if the element is found and removed from the list.
  • This method is going to return false, if the element is not present in the list.

Example 2: Here, we use the removeFirstOccurence() method to remove the first occurrence of an integer element from the LinkedList.


Output
[10, 20, 30, 20, 40]
First Occurence of 20 is removed: true
100 is present in the Linked List: false
[10, 30, 20, 40]
Comment