Recently I came across an API and it was using some Parameter
void doSomething(final String... olah) {
}
I never have seen something like that.
I have a List<String> now and I want to call that function with my list of string. How can I achieve that?
Welcome to modern Java. That syntax is called
varargsin Java.http://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html
You can think of it like
The only difference is that as the name suggests, it is Variable Length Arguments. You can invoke it with
0to any number or arguments. Thus,doSomething("foo"),doSomething("foo", "bar"),doSomething("foo", "bar", "baz")are all supported.In order to invoke this method with a
Listargument though, you’ll have to first convert the list into aString[].Something like this will do: