![]() |
VOOZH | about |
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.
[A, B, C, B, D] First Occurence of B is removed: true M is present in the Linked List: false [A, C, B, D]
public boolean removeFirstOccurrence(Object o)
Return Type:
Example 2: Here, we use the removeFirstOccurence() method to remove the first occurrence of an integer element from the LinkedList.
[10, 20, 30, 20, 40] First Occurence of 20 is removed: true 100 is present in the Linked List: false [10, 30, 20, 40]