Java Vector elementAt() MethodThe elementAt() method of Java Vector class is used to get the element at the specified index in the vector. SyntaxFollowing is the declaration of elementAt() method: Parameter
ReturnThe elementAt() method returns an element at the specified 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 at index 1 is = 2 Element at index 3 is = 4 Example 2Test it NowOutput: Element at 0th position = White Element at 2nd position = Black Example 3Test it NowOutput: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 >= 3 at java.base/java.util.Vector.elementAt(Vector.java:496) at myPackage.VectorElementAtExample3.main(VectorElementAtExample3.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