![]() |
VOOZH | about |
In Java, the lastIndexOf() method is used to find the index of the last occurrence of a specified element in an ArrayList.
Example 1: Here, we will use the lastIndexOf() method to find the index of the last occurrence of a specific element in an ArrayList of integers.
The last index of 22 is: 1
lastIndexOf() Methodpublic int lastIndexOf(Object o)
Example 2: Here, we use the lastIndexOf() method to find the last occurrence of an element in an ArrayList of strings.
The last index of Orange is: 2
Example 3: In this example, we will use the lastIndexOf() method with an ArrayList of custom objects. Here, we will find the last index of a specific object in the list.
The last index of Sweta is: 0