The java.util.vector.removeElementAt(int index) method is used to remove an element from a Vector from a specific position or index. In this process the size of the vector is automatically reduced by one and all other elements after the removed element are shifted downwards by one position.
Syntax:
Vector.removeElementAt(int index)
Parameters: This method accepts a mandatory parameter index of integer data type which specifies the position of the element to be removed from the Vector.
Return Value: This method has void return type. It means it does not return anything.
Below program illustrate the Java.util.Vector.remove(int index) method:
// Java code to illustrate removeElementAt() import java.util.*; public class VectorDemo { public static void main(String args[]) { // Creating an empty Vector Vector<String> vec_tor = new Vector<String>(); // Use add() method to add elements in the Vector vec_tor.add("Geeks"); vec_tor.add("for"); vec_tor.add("Geeks"); vec_tor.add("10"); vec_tor.add("20"); // Output the Vector System.out.println("Vector: " + vec_tor); // Initial size System.out.println("The initial size is: " + vec_tor.size()); // Remove the element at 3rd position vec_tor.removeElementAt(2); // Print the final Vector System.out.println("Final Vector: " + vec_tor); // Final size System.out.println("The final size is: " + vec_tor.size()); } } |
Vector: [Geeks, for, Geeks, 10, 20] The initial size is: 5 Final Vector: [Geeks, for, 10, 20] The final size is: 4
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- Stack removeElementAt() method in Java with Example
- Vector clear() Method in Java
- Vector addAll() Method in Java
- Vector set() Method in Java
- Vector isEmpty() Method in Java
- Vector lastIndexOf() Method in Java
- Vector addElement() Method in Java
- Vector subList() Method in Java
- Vector add() Method in Java
- Vector capacity() Method in Java
- Vector contains() Method in Java
- Vector containsAll() Method in Java
- Vector copyInto() Method in Java
- Vector indexOf() Method in Java
- Vector get() Method in Java
- Vector elementAt() Method in Java
- Vector elements() Method in Java
- Vector equals() Method in Java
- Vector size() Method in Java
- Vector hashCode() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

