Posted on 2007-09-19 13:06
流浪韓 閱讀(286)
評論(0) 編輯 收藏 所屬分類:
J2SE
引元數量可變的方法
public class Test {
public void test(String... body){
//String...代表String的數組,長度由傳進來時的數組長度決定
for (int i = 0; i < body.length; i++) {
System.out.print(body[i]);
}
System.out.println();
}
}
public class Main {
public static void main(String[] args) {
Test t=new Test();
t.test("hello,","hi");
t.test("good morning");
t.test("good afternoon,","good evening,","good night");
}
}
輸出結果:
hello,hi
good morning
good afternoon,good evening,good night