LinkedList lastIndexOf() Method in Java with Examples
The lastIndexOf(Object element) method of LinkedList class present inside java.util package is used to check and find the occurrence of a particular element in the list. If the element is present in the list then the lastIndexOf() method returns the index of the last occurrence of the element otherwise it returns -1. This method is used to find the last occurrence of a particular element in LinkedList.
Parameters: The parameter element is of the type LinkedList.
It refers to the element whose last occurrence is required to be checked.
Return Value: The position of the last occurrence of the element in the list otherwise if the element is not present in the list then the method returns -1. The returned value is of integer type.
LinkedList:[Geeks, for, Geeks, 10, 20] Last occurrence of Geeks is at index: 2 Last occurrence of 10 is at index: 3