How to add all items in a String array to a vector in Java?

addition, arrays, java, string, vector

Solution

The vector.addAll()takes a Collection in parameter. In order to convert array to Collection, you can use Arrays.asList():

My_Vector.addAll(Arrays.asList(My_Array));

Problem

My code looks like this : ``` Vector<String> My_Vector=new Vector<String>(); String My_Array[]=new String[100]; for (int i=0;i<100;i++) My_Array[i]="Item_"+i; ...... My_Vector.addAll(My_Array); ``` But I got an error message, what's the right way to do it, without looping to add each item ? Frank

Original source