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  

Vector:
  1. Vector class
  2. Create Vector objects
  3. Add elements to this vector
  4. Size and capacity
  5. Remove all elements from a vector
  6. Clone a vector
  7. Does it contain a certain element
  8. Copy elements in vector to an array
  9. Get Enumeration from this vector
  10. Compare two vectors
  11. Get element from vector
  12. Is vector empty
  13. Get element index
  14. Remove element from a vector
  15. Retain elements collection c has
  16. Replace element in a vector
  17. Get a sub list from a list
  18. Convert Vector to Array