public boolean remove(Object o): Finds and deletes the first occurrence of the object o. If Vector does not contain this object, the list remains unchanged.
In this code, we are removing two String values from Vector.
import java.util.Vector;Output:
public class RemoveVector {
public static void main(String[] args) {
Vector< String> vct = new Vector< String> ();
//add elements
vct.add("e1");
vct.add("e2");
vct.add("e3");
vct.add("e4");
vct.add("e5");
System.out.println("Before deletion:");
for(String e:vct)
System.out.println(e);
//remove the "e2" element
vct.remove("e2");
//remove the "e5" element
vct.remove("e5");
System.out.println("\nAfter deletion:");
for(String e:vct)
System.out.println(e);
}
}
Before deletion:
e1
e2
e3
e4
e5
After deletion:
e1
e3
e4
Commentaires (0)
Laisser un commentaire
Connectez-vous pour commenter
Rejoignez la discussion et partagez vos connaissances avec la communauté
Chargement des commentaires...