Thinking in Java 第五章
P200 看到参数的不定长,记录下来
1 public class OptionalTrailingArguments {
2 static void f(int required,String ... trailing){//不定长参数
3 System.out.print("required:"+required+" ");
4 for(String s:trailing)
5 System.out.print(s+" ");
6 System.out.println();
7 }
8
9 public static void main(String[] args){
10 f(1,"one");
11 f(2,"two","three");
12 f(0);
13 }
14 }
输出结果:
required:1 one
required:2 two three
required:0