Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

What does the method firstElement() do in java?



The firstElement() method is used to return the first component (the item at index 0) of this 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("First element is :"+vec.firstElement());
   }
}

Output

First element is :4
Updated on: 2020-02-25T10:09:47+05:30

155 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements