Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the highest index i such that Objects.equals(o, get(i)), or -1 if there is no such index.
Examples
package com.logicbig.example.arraylist;
import java.util.*;
public class LastIndexOfExample {
public static void main(String... args) { // Find last occurrence index ArrayList<String> list = new ArrayList<>(Arrays.asList("A", "B", "C", "B", "A")); int lastA = list.lastIndexOf("A"); int lastB = list.lastIndexOf("B"); System.out.println("Last A at: " + lastA); System.out.println("Last B at: " + lastB); } }