Vector contains(Object) in Java

contains(Object): This method is available in java.util.Vector class of Java.

Syntax:

boolean java.util.Vector.contains(Object o)

This method takes one argument. This method returns true if this vector contains the specified element.

Parameters: One parameter is required for this method.

o: element whose presence in this vector is to be tested.

Returns: true if this vector contains the specified element.

Exceptions: NA

Approach

Java

import java.util.Vector;

public class Vectorcontains {
    public static void main(String[] args) {

        Vector<String> vector = new Vector<>();

        vector.add("Hello");
        vector.add("Java");
        vector.add("C++");
        vector.add("Program");

        Object o = "Java";

        System.out.println(vector.contains(o));
    }
}

Output:

true


No comments:

Post a Comment