码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-06-29 16:40:27      阅读:100      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!