Dev/Java

variable arguments 2

냐옴 2014. 2. 14. 15:21

public class TestMain {


public static void main(String[] args) {

test();

test(1, null);

test("1", "2", null, 3);

}

private static void test(Object... args) {

System.out.println("---------------------------");

System.out.println("args.length : " + args.length);

for (Object obj : args) {

System.out.println("\t" + obj);

}

}

}


// output

---------------------------

args.length : 0

---------------------------

args.length : 2

1

null

---------------------------

args.length : 4

1

2

null

3



댓글수0