The java.util.vector.indexOf(Object element) method is used to check and find the occurrence of a particular element in the vector. If the element is present then the index of the first occurrence of the element is returned otherwise -1 is returned if the vector does not contain the element.
Parameters: This method accepts a mandatory parameter element of the type of Vector. It specifies the element whose occurrence is needed to be checked in the Vector.
Return Value: This method returns the index or position of the first occurrence of the element in the vector. Else it returns -1 if the element is not present in the vector. The returned value is of integer type.
Below programs illustrate the Java.util.Vector.indexOf() method:
Vector: [Geeks, for, Geeks, 10, 20] The first occurrence of Geeks is at index:0 The first occurrence of 10 is at index: 3
Vector: [1, 2, 3, 10, 20] The first occurrence of Geeks is at index:1 The first occurrence of 10 is at index: 4
- LinkedList indexOf() method in Java
- CopyOnWriteArrayList indexOf() method in Java
- AbstractSequentialList indexOf() method in Java with Example
- Stack indexOf() method in Java with Example
- Stack indexOf(Object, int) method in Java with Example
- AbstractList indexOf() method in Java with Examples
- StringBuffer indexOf() method in Java with Examples
- StringBuilder indexOf() method in Java with Examples
- List indexOf() Method in Java with Examples
- Java Guava | Ints.indexOf(int array, int target) method with Examples
- Vector set() Method in Java
- Vector get() Method in Java
- Vector add() Method in Java
- Vector contains() Method in Java
- Java Guava | Doubles.indexOf(double array, double target) method with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.