Tuesday 6 May 2014

Vector : contains : Search for an element

public boolean contains(Object o)
Return true if this vector contains the specified element

import java.util.*;

class VectorContains{
 public static void main(String args[]){
  Vector<Integer> myVector;
  myVector = new Vector<> ();
  
  /* Add Elements to myVector */
  for(int i=1; i < 6; i++)
   myVector.addElement(i);
   
  System.out.println("Elements in myVector are");
  System.out.println(myVector);
  
  System.out.print("\nIs myVector contains 10 ");
  System.out.println(myVector.contains(10));
  
  System.out.print("Is myVector contains 5 ");
  System.out.println(myVector.contains(5));
 }
}

Output
Elements in myVector are
[1, 2, 3, 4, 5]

Is myVector contains 10 false
Is myVector contains 5 true


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment