1. What is a variable parameter
Variable parameters are a new feature of JDK1.5, allowing a single way to accept any number of arguments
public static void Main (string[] args) {print ("a");p rint ("A", "B");p rint ("A", "B", "C"), and public static void print (String ... s) {for (String a:s) System.out.println (a);}
2. How the variable parameter is executed
When a variable parameter is used, an array is created where it is called, and the array length is the actual number of arguments;
The arguments are then put into the array, and finally the array is passed to the method
3. When to use variable parameters
mutable parameters, as defined by variable parameters, are very useful in accepting any number of objects;
Example of a mutable parameter in a JDK source code:
String.Format (String format, Object ... args), this method can accept any number of arguments
String.Format ("An Integer:%d", i); String.Format ("An integer:%d and a string:%s", I, s);
mutable parameters in Java