removeElement(Object): This method is available in java.util.Vector class of Java.
Syntax:
boolean java.util.Vector.removeElement(Object obj)
This method takes one argument. This method removes the first (lowest-indexed) occurrence of the argument from this vector.
Note: If the object is found in this vector, each component in the vector with an index greater or equal to the object's index is shifted downward to have an index one smaller than the value it had previously.
Parameters: One parameter is required for this method.
obj: the component to be removed.
Returns: true if the argument was a component of this vector; false otherwise.
Exceptions: NA
Approach
Java
import java.util.Vector;public class VectorremoveElement {public static void main(String[] args) {Vector<String> vector = new Vector<>();vector.add("Hello");vector.add("Java");vector.add("C++");vector.add("Program");Object obj = "C++";System.out.println(vector.removeElement(obj));}}
Output:
true
No comments:
Post a Comment