How can I convert in the quickest way String[]
to Vector<String>
?
views:
130answers:
5With Arrays.asList :
Vector<String> v = new Vector<String>(Arrays.asList(yourStringArray));
Resources :
Like so:
Vector<String> strings = new Vector<String>( Arrays.asList(yourStringArray ) );
Check this example : http://www.java2s.com/Code/Java/Collections-Data-Structure/ConvertanArraytoaVector.htm
It will look like :
String[] arr = { "1", "2", "3", "4" };
Vector<String> v = new Vector<String>(Arrays.asList(arr));
As mentioned above you can get a List created for you using Arrays.asList and then forcefully create a Vector. But, my question is if you absolutely need to use a Vector. Vector is synchronized http://download.oracle.com/javase/6/docs/api/java/util/Vector.html and you might not want this overhead. But, if you need synchronization would you consider developing againt the interface List and then use Collections.synchronizedList to achieve the synchronization? http://download.oracle.com/javase/6/docs/api/java/util/Collections.html#synchronizedList%28java.util.List%29
If you are using an API which requires the type Vector then this is of course not a choice...