Vector get()
Java Vector get() Method
Last Updated : 17 Mar 2025
The get() method of Java Vector class is used to get the element at the specified position in the vector.
Syntax
Following is the declaration of get() method:
Parameter
| DataType | Parameter | Description | Required/Optional |
|---|---|---|---|
| int | index | It is an index of the element which will be returned. | Required |
Return
The get() method returns the element at the specified index.
Exceptions
ArrayIndexOutOfBoundsException- This method has thrown an exception if the index is out of range i.e. index < 0 || index >= size().
Compatibility Version
Java 1.2 and above
Example 1
Output:
Element at index 1 is = 2 Element at index 3 is = 4
Example 2
Output:
Element at 0th position = White Element at 2nd position = Black
Example 3
Output:
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