This is called varargs.
This is the way to indicate that the last parameter is actually a array of the type mentioned. Then the arguments in the method call can have a variable amount. That is, after the fixed and mandatory arguments, they can count from zero to "infinite" arguments provided that it is of the declared type.
When accessing s
(in your example) remember that this variable is a array and must access it in this way.
Understand the difference between parameter and argument.
More details on What mean the reticence in the parameters of a method?
The return is not possible in this way, it only serves for parameters. Nor does it make sense to have something like this, after all this is a syntactic sugar. If you need to return multiple items you have to use one array or other normal data collection, such as a ArrayList
or even a previously defined class.
public String[] getStrings() {
return new String[] {"x", "y"};
}
I put in the Github for future reference.
Related: What mean the reticence in the parameters of a method?
– Math
@Math this answers what it means, but the main thing I want to know is how to elaborate a method that returns it to me so I pass as parameter in the other method, since it does not accept as parameter one
String[]
.– Tiago Ferezin