How to convert Vector <Integer> to int []?

Possible duplicate:
How to convert List <Integer> to int [] in Java?

Is there any way to convert the vector <Integer> to int []?

thank

+5
source share
4 answers

toArray()will do the conversion for you. Check out the link for javadoc for all methods Vector. It will be in the box Integer, not int, but you can work from there.

0
source
Integer[] sl = (Integer[]) myVector.toArray(new Integer[0]);
0
source

, . Object [], , .

, , , Integer []

0
source

You can use a loop to copy a vector to int[]

Vector<Integer> vector = ....
int count = 0, ints[] = new int[vector.size()];
for(int i: vector) ints[count++] = i;
0
source

All Articles