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
import java.util.*;
public class VectorDemo {
public static void main(String args[])
{
Vector<String> vec_tor = new Vector<String>();
vec_tor.add("Geeks");
vec_tor.add(" for ");
vec_tor.add("Geeks");
vec_tor.add(" 10 ");
vec_tor.add(" 20 ");
System.out.println("Vector: " + vec_tor);
System.out.println("The initial size is: " + vec_tor.size());
vec_tor.removeElementAt( 2 );
System.out.println("Final Vector: " + vec_tor);
System.out.println("The final size is: " + vec_tor.size());
}
}
|
Output:
Vector: [Geeks, for, Geeks, 10, 20]
The initial size is: 5
Final Vector: [Geeks, for, 10, 20]
The final size is: 4
Time complexity: O(n). // n is the size of the vector.
Auxiliary Space: O(1).
Feeling lost in the vast world of Backend Development? It's time for a change! Join our
Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:
- Comprehensive Course
- Expert Guidance for Efficient Learning
- Hands-on Experience with Real-world Projects
- Proven Track Record with 100,000+ Successful Geeks
Last Updated :
24 May, 2023
Like Article
Save Article