1import java.util.ArrayList;
2public class ArrayListIndexOfMethodExample
3{
4 public static void main(String[] args)
5 {
6 ArrayList<Integer> al = new ArrayList<Integer>(5);
7 al.add(8);
8 al.add(6);
9 al.add(5);
10 al.add(7);
11 al.add(9);
12 System.out.print("ArrayList values are: ");
13 for(Integer num : al)
14 {
15 System.out.print(num);
16 System.out.print(" ");
17 }
18 // indexOf() method to find index of 5
19 int position = al.indexOf(5);
20 System.out.println("\nElement 5 is at index: " + position);
21 }
22}