What does the method lastElement() do in java?

Java 8Object Oriented ProgrammingProgramming

The lastElement() method is used to return the last component 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("Last element: "+vec.lastElement());
   }
}

Output

Last element: 1
raja
Published on 08-Feb-2018 09:05:31
Advertisements