The example aims to remove a specified element from Java Vector by removeElement method.
Source Code
package com.beginner.examples;
import java.util.Vector;
public class RemoveElementFromVectorByObject {
public static void main(String[] args) {
//create Vector.
Vector vector = new Vector();
vector.add("A");
vector.add("B");
vector.add("C");
vector.add("D");
System.out.println("Before removal , Vector contains : ");
for(int index=0; index < vector.size(); index++) {
System.out.println(vector.get(index));
}
/*
*To remove a specified element from Vector use remove method.
*/
vector.remove("C");
System.out.println("After removal , Vector contains : ");
for(int index=0; index < vector.size(); index++) {
System.out.println(vector.get(index));
}
}
}
Output:
Before removal , Vector contains :
A
B
C
D
After removal , Vector contains :
A
B
D
References
Imported packages in Java documentation: