7

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

Is there some method to convert a Vector< Integer> to an int[]?

Thanks

Community
  • 1
  • 1
Alex Moreno
  • 729
  • 3
  • 8
  • 14

4 Answers4

0

toArray() will do the conversion for you. Check the link for the javadoc of all the methods Vector has. This will be the boxed Integer, not int, but you can work from there.

unholysampler
  • 17,141
  • 7
  • 47
  • 64
0
Integer[] sl = (Integer[]) myVector.toArray(new Integer[0]);
MarkPowell
  • 16,482
  • 7
  • 61
  • 77
0

Vector uses objects and not primary types. so you can only convert to an Object[], to convert to a primary type array you'd have to use an additional step.

with no further comments on what's the point of your code, I would say that Integer[] would acomplish the same thing

IvoC
  • 86
  • 7
0

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

Vector<Integer> vector = ....
int count = 0, ints[] = new int[vector.size()];
for(int i: vector) ints[count++] = i;
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130