java可变参数列表

 

 1 public class Test {
 2     static void list(Integer[] i) {
 3         for (Integer q : i) {
 4             System.out.print(q + "*");
 5         }
 6         System.out.println();
 7     }
 8     static void list(String...args){
 9         for (String q : args) {
10             System.out.print(q + "*");
11         }
12         System.out.println();
13     }
14     static void list(Integer a,String...args){     //添加不可变参数,防止方法调用矛盾
15         System.out.print(a+"*");
16         for (String q : args) {
17             System.out.print(q + "*");
18         }
19         System.out.println();
20     }
21     public static void main(String[] args) {
22 
23         Integer[] in = new Integer[] { 1, 2, 3, 4, 5, 1, 7, 100 +'a'};    //可变参数
24         list(in);
25         list();
26         list("ff","ds","df","h","hgg");
27         list(2,"rtr","er","tr","we");
28         
29     }
30 }

                                       附图:输出结果

posted @ 2012-11-08 15:22  hlb  阅读(256)  评论(0编辑  收藏  举报