LinkedList removeFirstOccurrence() Method in Java
The java.util.LinkedList.removeFirstOccurrence() 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.
Parameters: The method takes one parameter element which is to be removed from the list. The type Object should be the same as the elements in the list.
Return Value: The method returns boolean True if the list contains the specified element and is deleted, otherwisr it returns false.
Below programs illustrate the removeFirstOccurrence() method:
Program 1 :
List before removing the first Occurrence of "one" : [one, two, three, one] Returned Value : true List after removing the first Occurrence of "one" : [two, three, one]
Program 2 :
List before removing the first Occurrence of "10" : [10, 20, 30, 10] Returned Value : true List after removing the first Occurrence of "10" : [20, 30, 10]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.