public E remove(int index): Removes an element in a specific position from the Vector list and shifts all other elements to the left and decrements their indices. This method should return the object that was removed from Vector.
import java.util.Vector;Output:
public class RemoveIndexVector {
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);
//delete the item at the index 0
vct.remove(0);
//remove the element with the index 2
vct.remove(2);
System.out.println("\nAfter deletion:");
for(String e:vct)
System.out.println(e);
}
}
Before deletion:
e1
e2
e3
e4
e5
After deletion:
e2
e3
e5
Commentaires (0)
Laisser un commentaire
Connectez-vous pour commenter
Rejoignez la discussion et partagez vos connaissances avec la communauté
Chargement des commentaires...