import java.util.ArrayList; import java.util.List; public class ListIndexOfExample { public static void main(String[] args) { Listnumbers = new ArrayList<>(); numbers.add(10); numbers.add(20); numbers.add(30); numbers.add(40); int indexOfThirty = numbers.indexOf(30); System.out.println("Index of 30: " + indexOfThirty); // Output: 2 } }
import java.util.LinkedList; import java.util.List; public class ListIndexOfExample { public static void main(String[] args) { ListPackage library: The List interface is part of the Java Collections Framework, which is included in the java.util package. The List and its corresponding implementations (ArrayList, LinkedList, etc.) are also included in the java.util package.cities = new LinkedList<>(); cities.add("New York"); cities.add("Chicago"); cities.add("Los Angeles"); cities.add("Houston"); int indexOfChicago = cities.indexOf("Chicago"); System.out.println("Index of Chicago: " + indexOfChicago); // Output: 1 } }