Vector class lastElement() method example
Returns the last component of the vector.
Vector class lastElement() method example. This example shows you how to use lastElement()method.This method Returns the last component of the vector.
Here is the code:-
/*
* @Program that Returns the last component of the vector.
* LastElement.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class LastElement {
public static void main(String[] args) {
//Creating vector
Vector v = new Vector();
//Adding element to the vector
v.add("Rose");
v.add("India");
v.add("Rohini");
v.add("Girish");
//Creating Enumeration Interface
Enumeration e = v.elements();
System.out.print("Element of Vector is : ");
while (e.hasMoreElements()) {
System.out.print(e.nextElement() + "\t");
}
System.out.println();
System.out.print("Last Element of the Vector is :" + v.lastElement());
}
} |
Output of the program:-
Element of Vector is : Rose India Rohini Girish
Last Element of the Vector is :Girish |
|