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
转自:www.blogjava.net/hanbihui/archive/2007/09/19/146428.html
本文通过一个Java示例展示了如何使用可变参数方法。该方法允许传递任意数量的字符串参数,并将它们打印出来。示例包括不同长度的字符串数组调用。
1207

被折叠的 条评论
为什么被折叠?



