2:56 am - Friday July 20, 2018

Vector Example program to copy all elements of Vector to an Object Array using copyinto()

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
/**
 *@author :CandidJava.com
 *@descriptions : This program explain the function and use of copyInto() method
 */
import java.util.Vector;

class CopyElementsOfVectorToArray {
	public static void main(String[] args) {
		// creating Vector Object
		Vector v = new Vector();
		v.add("52");
		v.add("25");
		v.add("30");
		v.add("47");
		v.add("58");
		// Creating an Object for the Object class to store the elements in the
		// form of ArrayList
		Object[] objArray = new Object[5];
		// copyinto() method is used to copy all the elements fetched from
		// Vector
		v.copyInto(objArray);
		System.out
				.println("Vector elements are copied into an Array.Now Array Contains..");
		for (int index = 0; index < objArray.length; index++)
			System.out.println(objArray[index]);
	}
}

OUTPUT:

D:\CandidJava\Util\Vector>javac CopyElementsOfVectorToArray.java

Note: CopyElementsOfVectorToArray.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\Vector>java CopyElementsOfVectorToArray

Vector elements are copied into an Array.Now Array Contains..

52

25

30

47

58

BACK

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply