Methods to Search element within Vector
Vector provides following methods to search a particular element
within the Vector.
1) int indexOf(Object element)
Search for a particular element in the Vector and return the position
of the first occurrence of the element if found within the Vector,
otherwise returns -1.
2) int indexOf(Object element, int startIndex)
Search for a particular element in the Vector staring from the
startIndex specified and return the position of the first occurrence
of the element if found within the Vector, otherwise returns -1.
3) int lastIndexOf(Object element)
Search for a particular element in the Vector and return the position
of the last occurrence of the element if found within the Vector,
otherwise returns -1.
4) int lastIndexOf(Object element, int startIndex)
Search for a particular element in the Vector starting from startIndex
in backward direction and returns the position of the last occurrence
of the element if found within the Vector, otherwise returns -1.
5) int size()
Returns the number of elements contained in the Vector.
6) boolean isEmpty()
Returns true of the Vector is empty, otherwise returns false.
7) boolean contains(Object element)
Returns true if the specified element is found in the Vector, otherwise
returns false.
|