possible duplicate
As question was asked How to convert Vector to String array in java
which one is the best performance for store the vector value to String array. And how it will perform in background?
Vector<String> v = new Vector<String>();
// this one
String s[] = v.toArray(new String[v.size()]);
// or this one
String s[] = v.toArray(new String[0]);
As a general rule of thumb, it’s faster to properly size an array or collection the first time, because it prevents the need to resize it one or more times later. Less work == faster. BTW, you almost certainly shouldn’t be using a
Vector; anArrayListis a better choice in the vast majority of cases.UPDATE: For your particular case, the results are going to be heavily dependent on the data in your
Vector. As with any question about performance, you should profile it for yourself. Since you’ve said you don’t know how to benchmark, I suggest you read up on profiling and performance measurement for Java applications. If you aren’t measuring things, you shouldn’t waste your time worrying about the performance of standard library operations. You’re likely worrying about things that have nothing to do with the actual bottlenecks in your applications.