1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
/* Copy all elements of Java Vector to an Object Array Example This Java Example shows how to copy all elements of Java Vector object to an array using copyInTo method. */ import java.util.Vector; public class CopyElementsOfVectorToArrayExample { public static void main(String[] args) { //create a Vector object Vector v = new Vector(); //Add elements to Vector v.add("1"); v.add("2"); v.add("3"); v.add("4"); v.add("5"); //declare an array to hold elements of Vector Object[] objArray = new Object[5]; /* To copy all elements of java vector object into array use void copyInTo(Ojbect[] obj) method. Here obj is an array into which elements will get copied. Please note that the array should be big enough to hold all elements of java vector object. If not, ArrayIndexOutOfBoundException would be thrown. */ v.copyInto(objArray); //display contents of Object array 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 would be Vector elements are copied into an Array. Now Array Contains.. 1 2 3 4 5 */ |
how can i copy the contents into an integer array