Monday, 25 May 2015

How to find does Vector contains elements or not

we use contains() and  Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ?  e==null : o.equals(e)).


import java.util.Vector;

public class ContailsElement {
   
    public static void main(String[] args) {
      
        Vector<String> vector = new Vector<String>();
        //add element in vector
        vector.add("cricket");
        vector.add("hockey");
        vector.add("football");
        vector.add("tennish");
      
        // print vector
        System.out.println("Vector = "+vector);
      
        System.out.println(vector.contains("cricket"));
      
        System.out.println(vector.contains("apple"));
               
  }

}

Output:

 Vector = [cricket, hockey, football, tennish]

true

false

No comments:

Post a Comment