In Java, variable-length parameters (Varargs) can be defined for a method to match multiple parameters of an indeterminate quantity, defined as "...". In fact, this is similar to passing an array for the method, and the same is the same as the arrays on the use method:
public void Test (string ... str) {for
(string s:str) {
}
}
The calling method is the same as normal invocation, except that the parameters that can be matched are 0 to many. As follows:
Test ();
Test ("Lilei");
Test ("Lilei", "Hanmeimei");
The use of the process to pay attention to several points:
1, when the call, if the same time can match the fixed parameters and variable length parameters of the method, will first match the fixed parameter method.
2. If you can match 2 simultaneous methods that contain variable parameters, the compilation will complain because the compiler does not know which method to call.
3, a method can have only one variable parameter, and the variable parameter should be the last parameter.
The above about the variable length in Java definition and use of the method is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.