Online Java Compiler By
JavaTpoint.com
//Program to illustrate the lastElement() method import java.util.*; public class VectorLastElementExample3 { public static void main(String arg[]) { //Create an empty vector Vector
vecObj = new Vector
(4); //Add elements to the vector vecObj.add(101); vecObj.add(202); vecObj.add(303); vecObj.add(404); //Obtain the last element of this vector System.out.println("Last element of vector is: " +vecObj.lastElement()); //Use clear() method to remove all element of this vector vecObj.clear(); //Again obtain the last element of this vector after clear method System.out.println("The last element of a vector is: " +vecObj.lastElement()); } }
Output