In JAVA, variable-length parameters (Varargs) can be defined for methods to match multiple parameters with an uncertain number, and their definition is represented by "...". In fact, this is similar to passing an array for a method, and the usage method is the same as the array, as follows:
public void test(String... str){ for(String s : str){ } } The calling method is the same as the normal calling method, except that the parameters that can be matched are 0 to more than one. as follows:
test();test("lilei");test("lilei","hanmeimei");Some points to pay attention to during use:
1. When calling, if the method with fixed parameters and variable length parameters can be matched at the same time, the fixed parameter method will be preferred.
2. If you can match two methods containing mutable parameters at the same time, the compiler will report an error because the compiler does not know which method to call.
3. A method can only have one variable parameter, and the variable parameter should be the last parameter.
The above detailed explanation of the definition and usage methods of variable length parameters in Java is all the content I have shared with you. I hope you can give you a reference and I hope you can support Wulin.com more.