1.1.variable Parameters
Variable parameter refers to the number of arguments in a function that is undefined when the function is defined, and the caller can pass in a different number of arguments.
mutable parameters are defined in the following way, and mutable parameters can only be the last parameter of a function.
type ... Parameter name
mutable parameters are compiled into arrays, so they can be used as an array in a function.
/*** @Title: variableparametertest.java* @Package com.test.javatechnology* @Description:*@author http://www.cnblogs.com/coe2coe/* @date March 19, 2017 pm 8:21:44*@versionV1.0*/ Packagecom.test.javatechnology;/*** @ClassName: variableparametertest* @Description:*@author http://www.cnblogs.com/coe2coe/* @date March 19, 2017 pm 8:21:44**/ Public classVariableparametertest {Static voidTest (String name,int.. args) {inti; SYSTEM.OUT.PRINTLN (name); for(i=0;i<args.length;i++) {System.out.println (args[i]);}} /** * @paramargs*/ Public Static voidMain (string[] args) {Test ("Length is 0"); Test ("Length is 1", 10); Test ("Length is 2", 10, 20); } }
Variable parameters can be used as arrays, but if the last parameter is defined as an array, you cannot call this function
Used as a variable parameter.
Static void Test (String int[] args) {}
This function cannot be used in this way, or it will compile incorrectly.
Test ("length is 0");Test ("Length is 1", andtest ("length is 2", 10, 20);
Key Java Technology (2) variable parameters of syntax