Vector class toArray() method example
Returns an array containing all of the elements in this Vector in the correct order.
Vector class toArray() method example. This example shows you how to use toArray() method.This method Returns an array containing all of the elements in this Vector in the correct order.
Here is the code:-
/*
* @Program that Returns an array containing all of the elements in this Vector
//in the correct order.
* ToArray.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class ToArray {
public static void main(String[] args) {
//Creating Vector
Vector v = new Vector();
//Adding elements in the vector
v.add("A");
v.add("B");
v.add("G");
v.add("I");
v.add("R");
v.add("I");
v.add("S");
v.add("H");
// Returns an array containing all of the elements in this Vector in the
//correct order.
Object o[] = v.toArray();
System.out.println("Elements of the Object Array are: ");
for (int i = 2; i < v.size(); i++) //Displaying the element stored in the object Array
{
System.out.println(o[i]);
}
}
} |
Output of the program:-
Elements of the Object Array are:
G
I
R
I
S
H |
|