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

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
Updated on: 2019-07-30T22:30:20+05:30

256 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements