Javatpoint Logo
Javatpoint Logo

Java Vector setElementAt() Method

The setElementAt() method of Java Vector class is used to replace the component at the specified index of this vector to be the specified object.


Following is the declaration of setElementAt() method:


Parameter Description Required/Optional
index It is the specified index where an element will be replaced. Required
obj It is the component which will be set at the specified position. Required


This method has return type void so, it does not return anything.


ArrayIndexOutOfBoundsException- 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


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

Example 2

Test it Now


Vector element before setElementAt: [Java, Android, Python, COBOL]
Vector element after setElementAt: [Java, Android, Python, JavaTpoint]

Example 3

Test it Now


Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 500 >= 3
	at java.base/java.util.Vector.setElementAt(
	at myPackage.VectorSetElementAtExample3.main(

Youtube For Videos Join Our Youtube Channel: Join Now


  • Send your Feedback to

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA