![]() |
VOOZH | about |
In Java, the lastIndexOf() method of LinkedList is used to find the last occurrence of the specified element in the list. If the element is present it will return the last occurrence of the element, otherwise, it will return -1.
public int lastIndexOf(Object o);
Return type:
Example: Here, we use lastIndexOf() method to return the last occurrence of the specified element in the list.
[10, 20, 30, 40, 20, 40] Last occurrence of 30 is at index: 2 Last occurrence of 40 is at index: 5