Vector class get(int index)method example
Returns the element at the specified position in this Vector.
Vector class get(int index)method example. This example shows you how to use get(int index)method.This method Returns the element at the specified position in this Vector.
Here is the code:-
/*
* @Program that Returns the element at the specified position in this Vector.
* Get.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class Get {
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 element at the specified position in this Vector.
System.out.println("Element at index 2 of the Vector is: " + v.get(2));
}
} |
Output of the program:-
Vector created is: Rose India Rohini Girish
Element at index 2 of the Vector is: Rohini |
|