Java Vector get(int index) Example

The elementAt(int index) method of java.util.Vector class will get you the element at the specified index same way get(int index) method also returns the element at the specified index.


public E get(int index) 

Retrieves the element which is present at the particular index and will throw java.lang.ArrayIndexOutOfBoundsException if the index is not within the range


The following example shows the usage of java.util.Vector.get(index) method.

import java.util.Vector;

public class GetMethodVectorExample 
    public static void main(String args[])
        // create an empty Vector
        Vector vector1 = new Vector();
        // use add() method to add elements to the Vector
        //Getting element at a praticular index
        System.out.println("Element at index 1 is : "+vector1.get(1));


Element at index 1 is : Element2

Leave a Reply

Your email address will not be published. Required fields are marked *