Variable parameters:
1. Parameters can be passed without the limit of the number of arguments, all the parameters are stored in the form of an array.
2. Variable parameter definition Format: Return value type method name (Type ... Parameter name) {}, Note: ... Between the variable type and the variable name
3. The definition of an optional variable must be placed after the parameter list.
Why does the definition of a mutable parameter have to be placed behind the parameter list?
In the absence of a mutable parameter, Java is passing the accepted parameter type to an array, in the form of an array, traversing the method, requiring several elements to add several elements (public static void fun (int a[]) {}). Later there are parameter variables, although the form is changed, but the internal parameters are stored in the form of an array (public static void fun (int ... a)). ... What follows is an array that passes the arguments to the array and saves them, so if the definition of the mutable parameter is not placed after the argument list, the argument is not passed to the array as an array.
public class Newdemo02{public static void Main (String args[]) {System.out.print ("Do not pass parameter (fun ()):"), fun ();// Do not pass parameter System.out.print ("\ n pass a parameter (fun (1)):"), Fun (1),//pass a parameter System.out.print ("\ n pass five arguments (fun (1,2,3,4,5)):"); 1,2,3,4,5);} public static void Fun (int ... arg) {//variable parameter for (int x:arg) {//Use foreach output output System.out.print (x + ",");}};
New Java Features--variable parameters