Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.CopyOnWriteArrayList; public class CopyOnWriteArrayListLastIndexOfExample3{ public static void main(String[] args) { //Initializing CopyOnWriteArrayList of Strings CopyOnWriteArrayList
listOfNames = new CopyOnWriteArrayList<>(new String[] {"Tom","Harry","John","John","John","Jerry"}); //Prints the index of the last occurrence of the specified element in this list, searching backwards from index, or returns -1 if the element is not found. System.out.println("Last Index of John is : " + listOfNames.lastIndexOf("John", 5)); } }
Output