Java Vector setElementAt() MethodLast Updated : 17 Mar 2025 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. SyntaxFollowing is the declaration of setElementAt() method: Parameter
ReturnThis method has return type void so, it does not return anything. ExceptionsArrayIndexOutOfBoundsException- This method has thrown an exception if the index of an array is out of range i.e. (index < 0 || index >= size()). Compatibility VersionJava 1.2 and above Example 1Output: Vector element before setElementAt: [1, 2, 3, 4, 6] Vector element after setElementAt: [1, 2, 3, 4, 5] Example 2Output: Vector element before setElementAt: [Java, Android, Python, COBOL] Vector element after setElementAt: [Java, Android, Python, JavaTpoint] Example 3Output: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 500 >= 3 at java.base/java.util.Vector.setElementAt(Vector.java:552) at myPackage.VectorSetElementAtExample3.main(VectorSetElementAtExample3.java:12) Next TopicJava Vector Set Method |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India