VOOZH about

URL: https://www.geeksforgeeks.org/java/linkedlist-removelastoccurrence-method-in-java-with-example/

⇱ LinkedList removeLastOccurrence() method in Java with Example - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

LinkedList removeLastOccurrence() method in Java with Example

Last Updated : 21 Dec, 2022

The java.util.concurrent.LinkedList.removeLastOccurrence() method is an inbuilt method in Java which accepts a parameter and removes the last appearance of that element in the list. Thus, in case the element is not present in the list, it remains unchanged. Syntax:

public boolean removeLastOccurrence(Object o)

Parameters: The function accepts an object elem as parameter which denotes the object whose last appearance from the list is to be removed. Return Value: The function returns true if elem is present in the list and returns false otherwise. Below programs illustrate the use of removeLastOccurrence() method : 

Output:
LinkedList: [GFG, Geeks, Gfg, gfg, Geeks]
Removed last occurrence of 'Geeks' from the list
LinkedList: [GFG, Geeks, Gfg, gfg]

Program 2: 

Output:
LinkedList: [12, 280, 12, 1050, 12]
Removed last occurrence of '12' from the list
LinkedList: [12, 280, 12, 1050]
Comment