JAVA program for Vector.indexOf() Method
This JAVA program is to demonstrate the use of Vector.indexOf() method.
The indexOf() method returns the index of the element specified in the brackets.
Note : If the element at the index specified in the brackets is not present, then it returns -1.
Program
import java.util.*; class v8 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int i,n; Vector<Integer> v = new Vector<Integer>(); System.out.println("how many elements do you want to insert?"); n=sc.nextInt(); System.out.println("Start inserting the elements"); for(i=0;i<n;i++) { v.add(sc.nextInt()); } System.out.println("Enter the element of which you want to find the index of"); int el = sc.nextInt(); System.out.println("Index Of element("+el+") in the Vector = "+v.indexOf(el)); } }