As the title suggests, what is the best method for converting an array of strings to a vector?
Thanks
Vector strVector = new Vector(Arrays.asList(strArray));
Breaking this down:
Arrays.asList(array)
converts the array to a List
(which implements Collection
)
The Vector(Collection)
constructor takes a Collection
and instantiates a new Vector
based off of it.
We pass the new List
to the Vector
constructor to get a new Vector
from the array of String
s, then save the reference to this object in strVector
.