Vector class firstElement()method example
Returns the first component (the item at index 0) of this vector.
Vector class firstElement()method example. This example shows you how to use firstElement()method.This method Returns the first component (the item at index 0) of this vector.
Here is the code:-
/*
* @Program that Returns the first component (item at index 0) of this vector.
* FirstElement.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class FirstElement {
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("Vector created is: ");
while (e.hasMoreElements()) {
System.out.print(e.nextElement() + "\t");
}
System.out.println();
//Returns the first component (item at index 0) of this vector.
System.out.println("Element at First position of the Vector is: " + v.firstElement());
}
} |
Output of the program:-
Vector created is: Rose India Rohini Girish
Element at First position of the Vector is: Rose |
|