Online Java Compiler By
JavaTpoint.com
//Program to illustrate the lastElement() method import java.util.*; public class VectorLastElementExample2 { public static void main(String arg[]) { //Create an empty vector Vector
vectorObject = new Vector
(4); //Add elements to the vector vectorObject.add(11); vectorObject.add(22); vectorObject.add(33); vectorObject.add(44); //Displaying the vector list System.out.println("Element of a vector is: " +vectorObject); //Obtain the last element of this vector System.out.println("The last element of a vector is: " +vectorObject.lastElement()); } }
Output