Java Vector insertElementAt() MethodThe insertElementAt() method of Java Vector class is used to insert the specified object as a component in this vector at the specified index. Each component in the vector with an index greater or equal to the given index is shifted upward. Now, the vector index is one greater than the value it had previously. SyntaxFollowing is the declaration of insertElementAt() method: Parameter
ReturnThe insertElementAt() method does not return anything. It only inserts an element at the given index. ExceptionsArrayIndexOutOfBoundsException- This method has thrown an exception if the index is out of range i.e. index < 0 || index >= size(). Compatibility VersionJava 1.2 and above Example 1Test it NowOutput: Element in vector before insertion = [10, 20, 30, 40, 50] Element in vector after insertion = [10, 20, 700, 30, 40, 50] Example 2Test it NowOutput: Components of vector: Java Ruby Android Python Components of vector after insertion = Java PHP Ruby Android Python Example 3Test it NowOutput: Color elements in vector: [White, Green, Black] Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 12 > 3 at java.base/java.util.Vector.insertElementAt(Vector.java:619) at myPackage.VectorInsertElementAtExample3.main(VectorInsertElementAtExample3.java:14) Next TopicJava Vector |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India