public class JavaTest {
public static void main(String[] args) {
test();
test("1");
test("1", "2");
String[] strs = {"1", "2", "3"};
test(strs);
}
public static void test(String... str) {
System.out.println("--------------");
System.out.println("个数:" + str.length);
if(str.length > 0) {
for(String s : str) {
System.out.print(s + " ");
}
System.out.println();
for(int i = 0; i < str.length; i++) {
System.out.print(str[i] + " ");
}
System.out.println();
}
System.out.println("--------------");
test2(str);
}
public static void test(String str) {
System.out.println("+++++++++++++"+str);
}
public static void test2(String[] str) {
System.out.println("******************");
System.out.println("个数:" + str.length);
if(str.length > 0) {
for(String s : str) {
System.out.print(s + " ");
}
System.out.println();
}
System.out.println("******************");
}
输出
--------------
个数:0
--------------
******************
个数:0
******************
+++++++++++++1
--------------
个数:2
1 2
1 2
--------------
******************
个数:2
1 2
******************
--------------
个数:3
1 2 3
1 2 3
--------------
******************
个数:3
1 2 3
******************