Last Updated : 11 Jul, 2025
In Java, the elementAt() method is used to fetch or retrieve an element at a specific index from a Vector. It allows to access elements in the vector by providing the index, which is zero-based.
Example 1: Here, we use the elementAt() method to retrieve an element at a specified index with an Integer type.
Java
// Java program to Demonstrate the
// use of elementAt() with Integer type
import java.util.Vector;
public class Geeks {
public static void main(String args[])
{
// Creating an empty Vector
Vector<Integer> v = new Vector<>();
// Use add() method to
// add elements in the Vector
v.add(10);
v.add(20);
v.add(30);
v.add(40);
v.add(50);
System.out.println(" " + v);
// Fetching the specific element from the Vector
System.out.println(" The element is: "
+ v.elementAt(3));
}
}
[10, 20, 30, 40, 50] The element is: 40Syntax of Vector element() Method
public E elementAt(int index)
Example 2: Here, we use the elementAt() method to retrieve an element at a specified index with String type.
Java
// Java program to Demonstrate the use of elementAt() with String type
import java.util.Vector;
public class Geeks {
public static void main(String args[])
{
// Creating an empty Vector
Vector<String> v = new Vector<>();
// Use add() method to
// add elements in the Vector
v.add("Geeks");
v.add("for");
v.add("Geeks");
System.out.println(" " + v);
// Fetching the specific element from the Vector
System.out.println(" The element is: "
+ v.elementAt(1));
}
}
[Geeks, for, Geeks] The element is: for
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4