Vector class remove(int index) method example
Removes the element at the specified position in this Vector.
Vector class remove(int index) method example. This example shows you how to use remove(int index) method.This method Removes the element at the specified position in this Vector.
Here is the code:-
/*
* @Program that Removes the element at the specified position in this Vector.
* Remove.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class Remove {
public static void main(String[] args) {
//Creating vector
Vector v = new Vector();
//Adding element to the vector
v.add("Rose");
v.add("India");
v.add("Rohini");
v.add("Girish");
v.add("Rose");
//Creating Enumeration Interface
Enumeration e = v.elements();
System.out.print("Element of Vector is : ");
while (e.hasMoreElements()) {
System.out.print(e.nextElement() + "\t");
}
System.out.println();
//Removes the element at the specified position in this Vector.
System.out.print("Removed Element is: " + v.remove(3));
System.out.println();
Enumeration e1 = v.elements();
System.out.print("Element of Vector after removing is : ");
while (e1.hasMoreElements()) {
System.out.print(e1.nextElement() + "\t");
}
}
} |
Output of the program:-
Element of Vector is : Rose India Rohini Girish Rose
Removed Element is: Girish
Element of Vector after removing is : Rose India Rohini Rose |
|