Skip to main content

toArray to accept primative arrays

No replies
Joined: 2004-11-26

It would be nice (in Vector, and ArrayList) to accept primative arrays in the toArray function and unwrap these when it is put into the array. E.g.

<br />
Vector vector = new Vector();<br />
vector.add(1);<br />
vector.add(2);<br />
vector.add(3);<br />
vector.add(4);<br />
int[] values = new int[vector.size()];<br />
vector.toPrimativeArray(values);<br />

Note that toArray cannot be extended to include primative arrays since it takes in a T[] (which means it must be an Object[])

Another thing that would be nice is if java.util.Arrays had a convert method to convert wrapped arrays to their primative counter parts.