varags. If a method signature is method(Param param, String... x) it will take one Param type of object and any number of String objects.
There are couple if cool things about it:
It's nothing special. It's just sugared array. So,
method(MyObject... o)is same asmethod(MyObject[] o).Vararg has to be the last parameter in argument list.
There is this funny thing that bit me once.
method(MyObject... o)can be called asmethod()without any compilation error. Java will internally convert the no-arg call tomethod(new MyObject[0]). So, be aware of this.
android - What is "String..." in java? - Stack Overflow
String templates: syntax question
It looks like JDK20 is getting a String Templates preview!
Array type annotation syntax: String[] -vs- [String]
Videos
varags. If a method signature is method(Param param, String... x) it will take one Param type of object and any number of String objects.
There are couple if cool things about it:
It's nothing special. It's just sugared array. So,
method(MyObject... o)is same asmethod(MyObject[] o).Vararg has to be the last parameter in argument list.
There is this funny thing that bit me once.
method(MyObject... o)can be called asmethod()without any compilation error. Java will internally convert the no-arg call tomethod(new MyObject[0]). So, be aware of this.
It's syntax for writing the items of the array as a parameter
for instance:
public String first (String... values) {
return values[0];
}
Then you can call this method with first("4","2","5","67")
The javacompiler will create an array of the parameters on its own.