Java Vector removeElementAt() Method
The removeElementAt() method of Java Vector class is used to delete the component at the specified index. Each element in this vector with an index greater or equal to the given index is shifted downward. Now the vector index is one smaller than the value it had previously.
Following is the declaration of removeElementAt() method:
This method does not return anything. It only removed the element from the vector.
IndexOutOfBoundsException- This method has thrown an exception if the index of an array is out of range i.e. (index < 0 || index >= size()).
Java 1.2 and above
Example 1Test it Now
Vector element before removal: [1, 2, 3, 4, 5, 6] Vector element after removal: [1, 2, 3, 4, 5]
Example 2Test it Now
The elements of a vector before removal: [Rahul, Karan, Rahul, Rohan] The elements of a vector after removal: [Rahul, Karan, Rohan]
Example 3Test it Now
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 50 >= 3 at java.base/java.util.Vector.removeElementAt(Vector.java:579) at myPackage.VectorRemoveElementAtExample3.main(VectorRemoveElementAtExample3.java:12)