Java Vector removeElementAt() MethodThe 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. SyntaxFollowing is the declaration of removeElementAt() method: Parameter
ReturnThis method does not return anything. It only removed the element from the vector. ExceptionsIndexOutOfBoundsException- 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 1Test it NowOutput: Vector element before removal: [1, 2, 3, 4, 5, 6] Vector element after removal: [1, 2, 3, 4, 5] Example 2Test it NowOutput: The elements of a vector before removal: [Rahul, Karan, Rahul, Rohan] The elements of a vector after removal: [Rahul, Karan, Rohan] Example 3Test it NowOutput: 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 |
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