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

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 08-Feb-2018 09:12:56
Advertisements