- public static void main(String[] args) {
- callMe1(new String[] { "a", "b", "c" ,"d"});
- callMe2("a", "b", "c" ,"d");
- // You can also do this
- // callMe2(new String[] {"a", "b", "c"});
- }
- public static void callMe1(String[] args) {
- System.out.println(args.getClass() == String[].class);
- for (String s : args) {
- System.out.println(s);
- }
- }
- public static void callMe2(String... args) {
- System.out.println(args.getClass() == String[].class);
- for (String s : args) {
- System.out.println(s);
- }
- }
测试 结果:
- true
- a
- b
- c
- d
- true
- a
- b
- c
- d
通过这个小测试,应该可以看出来。
方法一是传统的参数类型:字符串数组类型;
方法二是可以传递一个或多个string类型的参数,不限制参数个数。