问题
List<String> strings;
void takeParams(String... params);
How can I pass the list into that a method only taking varargs?
strings.toArray();
is not possible as it returns Object[]
.
回答1:
Use the List#toArray(T[]) method to create an array from the list, and pass it.
takeParams(strings.toArray(new String[strings.size()]));
来源:https://stackoverflow.com/questions/19951470/how-to-pass-a-list-as-parameter-for-varargs