Vector class remove(Object o)method example
Removes the first occurrence of the specified element in this Vector
Vector class remove(Object o) method example. This example shows you how to use remove(Object o) method.This method Removes the first occurrence of the specified element in this Vector If the Vector does not contain the element, it is unchanged.
Here is the code:-
/*
* @Program that Removes the first occurrence of the specified element in this
Vector
* Remove1.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class Remove1 {
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 first occurrence of the specified element in this Vector
System.out.println("Element is removed : " + v.remove("Rose"));
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
Element is removed : true
Element of Vector after removing is : India Rohini Girish Rose |
|