When a parameter is passed in Java, it is followed by the use of "..." after the type:
public static void Main (string[] args) {
Teststringargs ();//no parameter passed in
Teststringargs ("one");//a parameter passed in
Teststringargs ("One", "two", "three"),//3 string parameter passed in
Teststringargs (New string[]{"One", "two", "three"});//You can see that passing in three String arguments and passing in an array of length 3 results in the same example
Teststringargs (New string[]{"One", "one", "one", "three"},new string[]{"one", "one", "three"});//This will prompt an error.
Testintegerargs ();
Testintegerargs (1);
Testintegerargs (a);
Testintegerargs (New integer[]{1,2,3});
}
//somewhat similar to () and (String s1,string s2 ...) and (string[] s) 3 combined functions.
public static void Teststringargs (String ... s) {
if (s.length==0) {
System.out.println ("0 parameters passed in");
}else if (s.length==1) {
System.out.println ("1 parameters passed in");
}else{
SYSTEM.OUT.PRINTLN ("Multiple parameters passed in, each parameter is as follows:");
for (int i=0;i<s.length;i++) {
System.out.println ("the" + (i+1) + "parameters are" +s[i]+ ";");
}
System.out.println ();
}
}
public static void Testintegerargs (Integer ... ints) {
if (ints.length==0) {
System.out.println ("0 integer parameters passed in");
}else if (ints.length==1) {
System.out.println ("1 integer parameters passed in");
}else{
SYSTEM.OUT.PRINTLN ("Multiple parameters passed in, each parameter is as follows:");
for (int i=0;i<ints.length;i++) {
System.out.println ("the" + (i+1) + "integer parameter is" +ints[i]+ ";");
}
System.out.println ();
}
}
Operation Result:
0 parameters passed in
1 parameters passed in
Multiple parameters are passed in, each with the following parameters:
The 1th parameter is one;
The 2nd parameter is two;
The 3rd parameter is three;
//
Multiple parameters are passed in, each with the following parameters:
The 1th parameter is one;
The 2nd parameter is two;
The 3rd parameter is three;
//
0 integer parameters passed in
1 integer parameters passed in
Multiple parameters are passed in, each with the following parameters:
The 1th integer parameter is 1;
The 2nd integer parameter is 2;
The 3rd integer parameter is 3;
//
Multiple parameters are passed in, each with the following parameters:
The 1th integer parameter is 1;
The 2nd integer parameter is 2;
The 3rd integer parameter is 3;
"Java Learning Note 27" method for Java8 multiple parameters