Does it contain a certain element
boolean contains(Object o)
- Returns true if this vector contains the specified element.
boolean containsAll(Collection<?> c)
- Returns true if this Vector contains all of the elements in the specified Collection.
import java.util.Vector;
public class Main{
public static void main(String args[]) {
Vector v = new Vector(2000);
v.add("java2s.com");
boolean b = v.contains("java2s.com");
System.out.println(b);
}
}
The output:
true
Search an element of Vector
import java.util.Vector;
public class Main {
public static void main(String[] args) {
Vector v = new Vector();
v.add("1");
v.add("2");
v.add("3");
v.add("4");
v.add("5");
v.add("1");
v.add("java2s.com");
boolean blnFound = v.contains("3");
System.out.println("contain 3: " + blnFound);
int index = v.indexOf("5");
if (index == -1)
System.out.println("does not contain 5");
else
System.out.println("5 at index :" + index);
int lastIndex = v.lastIndexOf("2");
if (lastIndex == -1)
System.out.println("does not contain 2");
else
System.out.println("Last occurrence of 2:" + lastIndex);
}
}
The output:
contain 3: true
5 at index :4
Last occurrence of 2:1
Home
Java Book
Collection
Java Book
Collection
Vector:
- Vector class
- Create Vector objects
- Add elements to this vector
- Size and capacity
- Remove all elements from a vector
- Clone a vector
- Does it contain a certain element
- Copy elements in vector to an array
- Get Enumeration from this vector
- Compare two vectors
- Get element from vector
- Is vector empty
- Get element index
- Remove element from a vector
- Retain elements collection c has
- Replace element in a vector
- Get a sub list from a list
- Convert Vector to Array