I have a vector of float arrays i.e. Vector . I want to convert this to one float array i.e. move every element in every float[] within the vector to a new float[]. Am a bit puzzled on using the Java built in method vector.toArray() to do this. Any ideas pls?
Share
There are several ways to do this. You can invoke
toArray()to get several arrays, and then join them into one big array (Guava has utility method to do this). Or you can allocate one big array and then useSystem.arraycopyto copy the components array into the appropriate portion of the big array.Here’s an example of the latter:
With Guava, it looks like you can do this with one line using
Floats.concat(float[]...):See also
It should also be noted that unless you need the thread-safety of
Vector, you should probably useArrayListinstead.See also