Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.CopyOnWriteArrayList; public class CopyOnWriteArrayListIndexOfExample4{ public static void main(String[] args) { //Initializing CopyOnWriteArrayList of Strings CopyOnWriteArrayList
listOfNames = new CopyOnWriteArrayList<>(new String[] {"Tom","Harry","John","John"}); //Prints index of the first occurrence of the element in this list at position index or later in the list and -1 if the element is not found. System.out.println("Index of Jerry is : " + listOfNames.indexOf("Jerry", 1)); } }
Output