Java Vector set() MethodThe set() method of Java Vector class is used to replace the element at the specified position in the vector with the specified element. SyntaxFollowing is the declaration of set() method: Parameter
ReturnThe set() method returns the element that was previously stored at the specified position. 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 1Test it NowOutput: Vector element before set: [1, 2, 3, 4, 6] Vector element after set: [1, 2, 3, 4, 5] Example 2Test it NowOutput: Vector element before set: [Java, Android, Python, COBOL] Vector element after set: [Java, Android, Python, JavaTpoint] Example 3Test it NowOutput: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 15 at java.base/java.util.Vector.set(Vector.java:798) at myPackage.VectorSetExample3.main(VectorSetExample3.java:12) Next TopicJava Vector Setsize Method |
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