Javatpoint Logo
Javatpoint Logo

Java Vector get() Method

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

Test it Now

Output:

Element at index 1 is = 2
Element at index 3 is = 4

Example 2

Test it Now

Output:

Element at 0th position = White
Element at 2nd position = Black

Example 3

Test it Now

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





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA