java .. 用法

来源:百度知道 编辑:UC知道 时间:2024/05/26 19:47:36
public class Test02 {
static void f(int r,String... str){
System.out.print("r="+r+" ");
for(String s:str)
System.out.print(s+" ");
System.out.println();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
f(1,"one");
f(2,"two","three");
f(0);

}

}
那个。。。 有什么用啊 ?是什么作用? 怎么用的?去掉了 下面的调用就有错!

那个表示后面可以有很多个那种类别的参数,调用时存在一个array里面。相当于:
static void f(int r, String[] str)

f(1, new String[] {"one"});
f(2, new String[] {"two", "three"});
f(0, new String[] {});