Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.CopyOnWriteArrayList; public class CopyOnWriteArrayListIndexOfExample3{ 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 John is : " + listOfNames.indexOf("John", 1)); } }
Output