This section demonstrates how to use the indexOf() method in Java Program.
This section demonstrates how to use the indexOf() method in Java Program.
import java.util.*; public class List1 { public static void main(String[] args) { String ar[]={"india","pakistan","United Kingdom","Japan"}; List list=new ArrayList(); list.add(ar[0]); list.add(ar[1]); list.add(ar[2]); list.add(ar[3]); System.out.println(list.indexOf("Japan")); System.out.println(list.indexOf(ar[2])); } } Output 3 2