Javatpoint Logo
Javatpoint Logo

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.

Syntax

Following is the declaration of removeElementAt() method:

Parameter

DataType Parameter Description Required/Optional
int index It is an index of the object which will be removed. Required

Return

This method does not return anything. It only removed the element from the vector.

Exceptions

IndexOutOfBoundsException- This method has thrown an exception if the index of an array is out of range i.e. (index < 0 || index >= size()).

Compatibility Version

Java 1.2 and above

Example 1

Test it Now

Output:

Vector element before removal: [1, 2, 3, 4, 5, 6]
Vector element after removal: [1, 2, 3, 4, 5]

Example 2

Test it Now

Output:

The elements of a vector before removal: [Rahul, Karan, Rahul, Rohan]
The elements of a vector after removal: [Rahul, Karan, Rohan]

Example 3

Test it Now

Output:

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)

Next TopicJava Vector





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback

  • Send your Feedback to feedback@javatpoint.com

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA