The lastIndexOf() method of ArrayList in Java is used to get the index of the last occurrence of an element in an ArrayList object.
Parameter : The element whose last index is to be returned.
It returns the last occurrence of the element passed in the parameter. It returns -1 if the element is not found.
Program to demonstrate the working of lastIndexOf():
The list initially [10, 20, 30, 40, 30, 30, 40] the lastIndexof of 30 is 5 100 is not present in the list
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.