Java ArrayList.lastIndexOf() Method
public int lastIndexOf(Object o)
The lastIndexOf() method is used to get the index of the last occurrence of an element in an ArrayList object.
Package : java.util
Java Platform : Java SE 8
Syntax:
lastIndexOf(Object o)
Parameters:
Name | Description |
---|---|
o | The element whose index is to be returned. |
Return Value:
The index of the last occurrence of an element in an ArrayList object, or -1 if the element does not exist.
Return Value Type: int
Pictorial presentation of ArrayList.lastIndexOf() Method

Example: ArrayList.lastIndexOf Method
The following example creates an ArrayList containing various colors. It then tries to determine the last position of a certain color.
Output:
F:\java>javac test.java F:\java>java test Size of list: 5 Value = White Value = Black Value = Red Value = White Value = Yellow The last occurrence of White color is at :3 The last occurrence of Red color is at :2
Java Code Editor:
Previous:indexOf Method
Next:clone Method