首页 > 其他 > 详细

String... args 和 String[] args 的区别

时间:2015-06-29 16:38:48      阅读:148      评论:0      收藏:0      [点我收藏+]
 1 public static void main(String[] args) {  
 2         callMe1(new String[] { "a", "b", "c" ,"d"});  
 3         callMe2("a", "b", "c" ,"d");  
 4         // You can also do this  
 5         // callMe2(new String[] {"a", "b", "c"});  
 6     }  
 7   
 8     public static void callMe1(String[] args) {  
 9         System.out.println(args.getClass() == String[].class);  
10         for (String s : args) {  
11             System.out.println(s);  
12         }  
13     }  
14   
15     public static void callMe2(String... args) {  
16         System.out.println(args.getClass() == String[].class);  
17         for (String s : args) {  
18             System.out.println(s);  
19         }  
20     }  

输出结果:

true  
a  
b  
c  
d  
true  
a  
b  
c  
d  

  

方法一是传统的参数类型:字符串数组类型;

方法二是可以传递一个或多个string类型的参数,不限制参数个数。

String... args 和 String[] args 的区别

原文:http://www.cnblogs.com/mlj5288/p/4607501.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!