To get index of
ArrayList
in Java, use the indexOf
method.Here's how you do it:
var list = new java.util.ArrayList<>(java.util.List.of("Hello", "World", "!"));
int indexOfWorld = list.indexOf("World");
System.out.println(indexOfWorld); // 1