Vector class removeElementAt(int index) method example
Deletes the component at the specified index.
Vector class removeElementAt(int index) method example. This example shows you how to use removeElementAt(int index) method.This method Deletes the component at the specified index.
Here is the code:-
/*
* @Program that Deletes the component at the specified index.
* RemoveElementAt.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class RemoveElementAt {
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");
}
//Deletes the component at the specified index.
v.removeElementAt(2);
Enumeration e1 = v.elements();
System.out.println();
System.out.print("Elements of the vector after removing element at specified index 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 at specified index is : Rose India |
|