What does the method elementAt(int index) do in java?


The elementAt(int index) method is used to get the component at the specified index/location of the vector.

Example

import java.util.Vector;
public class VectorDemo {
   public static void main(String[] args) {

      Vector<Integer> vec = new Vector<Integer>(4);
      vec.add(4);
      vec.add(3);
      vec.add(2);
      vec.add(1);
      System.out.println("Element at 1st position :- "+vec.elementAt(1));
   }
}

Output

Element at 1st position :- 3

Vikyath Ram
Vikyath Ram

A born rival

Updated on: 30-Jul-2019

151 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements