3:31 am - Saturday August 19, 2017

Vector Example Program for toArray(T[] a)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

/*Program Name: Vector Example Program for toArray(T[] a)*/
/**
*@Author: Candidjava.com
*@Description:Vector Example Program for toArray(T[] a)
Method is used to Returns an array containing all of the elements in this Vector in the correct
order. the runtime type of the returned array is that of the specified array.
*/

import java.util.*;


public class CollectionVector2
{
public static void main(String args[])
{
Vector<Integer> v1=new Vector<Integer>(); // creating vector objects.
Integer[] a=new Integer[5];
v1.add(1); //initialize v1 and adding elemnts.
v1.add(7);
v1.add(2);
v1.add(6);
v1.toArray(a); // adding all the elements from v1 to v2 starting at index 1.
System.out.println("The elements are:");
for(Object ob:a)
System.out.println(ob); //printing the result.

}

Output:

The elements are:
1
7
2
6
null

Filed in: Z-A All Java Codes

Comments are closed.