Vector class removeElement(Object obj) method example
Removes the first (lowest-indexed) occurrence of the argument from this vector
Vector class removeElement(Object obj) method example. This example shows you how to use removeElement(Object obj) method.This method Removes the first (lowest-indexed) occurrence of the argument from this vector
Here is the code:-
/*
* @Program that Removes the first (lowest-indexed) occurrence of the argument
from this vector.
* RemoveElement.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class RemoveElement {
public static void main(String[] args) {
Vector v = new Vector();
v.add("Rose");
v.add("India");
v.add("Rohini");
Enumeration e = v.elements();
System.out.print("Elements of the vector is : ");
while (e.hasMoreElements()) {
System.out.print(e.nextElement() + "\t");
}
//Removes the first (lowest-indexed) occurrence of the argument from this vector.
v.removeElement("Rohini");
Enumeration e1 = v.elements();
System.out.println();
System.out.print("Elements of the vector after removing element is: ");
while (e1.hasMoreElements()) {
System.out.print(e1.nextElement() + "\t");
}
}
} |
Output of the program:-
Elements of the vector is : Rose India Rohini
Elements of the vector after removing element is: Rose India |
|