We can use the following API to search element in a list.
public int indexOf(Object element) public int lastIndexOf(Object element)
return -1 if the element is not found.
import java.util.Arrays; import java.util.List; public class Main { public static void main(String[] a) { List<String> list = Arrays.asList( new String[] { "CSS", "HTML", "Java", "Javascript","CSS" }); System.out.println(list.lastIndexOf("CSS")); System.out.println(list.indexOf("CSS")); //from w w w . ja va 2 s . co m System.out.println(list.indexOf("demo2s.com")); } }