java.util.Vector.get() Method
Advertisements
Description
The get(int index) method is used to return the element at the specified index position in this Vector.
Declaration
Following is the declaration for java.util.Vector.get() method
public E get(int index)
Parameters
index--This is the index position of the element to be returned
Return Value
The method call returns the object at the specified index.
Exception
ArrayIndexOutOfBoundsException--This exception is thrown if the accessed index/position is out of range.
Example
The following example shows the usage of java.util.Vector.get() method.
package com.tutorialspoint;
import java.util.Vector;
public class VectorDemo {
public static void main(String[] args) {
// create an empty Vector vec with an initial capacity of 4
Vector vec = new Vector(4);
// use add() method to add elements in the vector
vec.add(4);
vec.add(3);
vec.add(2);
vec.add(1);
// let us get the 3rd element of the vector
System.out.println("Third element is :"+vec.get(3));
}
}
Let us compile and run the above program, this will produce the following result:
Third element is :1