Variable length parameter
- JDK5 provides variable length parameters
- grammar
类型...变量名
- There can be only one variable length parameter, and it must be the last position in the parameter list
- If the fixed parameter and variable length parameter method can be matched at the same time, the fixed parameter method will be matched first
- Variable length parameters can be treated as an array
public class Test {
public static void main(String[] args) {
l();
l(1);
l(3,34);
z(0);
z(2, "lv");
z(5, "may","day");
j("lv","may","day");
String[] m = {
"1","2","3"};
j(m);
j(new String[] {
"a","b","c"});
}
public static void l(int...k) {
System.out.println("lzjfw");
}
public static void z(int a,String...w) {
}
public static void j(String...r) {
for(int i = 0;i < r.length;i++) {
System.out.println(r[i]);
}
}
}