Java Vector get() MethodThe get() method of Java Vector class is used to get the element at the specified position in the vector. SyntaxFollowing is the declaration of get() method: Parameter
ReturnThe get() method returns the 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: Array index out of range: 5 at java.base/java.util.Vector.get(Vector.java:780) at myPackage.VectorGetExample3.main(VectorGetExample3.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