Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Search elements in Java Vector using indexOf, lastIndexOf, size and contains methods

Methods to Search element in 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.


<< Java Vector Constructors    Java Vector Add Replace Elements >>
No votes yet
Share this

Post new comment