隨筆 - 119  文章 - 3173  trackbacks - 0
          <2006年12月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          交友莫獨酒,茅臺西鳳游。
          口干古井貢,心徜洋河流。
          稱多情杜康,趟無量雙溝。
          贊中華巍巍,無此不銷愁。

          常用鏈接

          留言簿(68)

          隨筆分類(136)

          隨筆檔案(122)

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 526817
          • 排名 - 92

          最新評論

          ??? 今天整理以前的一些零碎代碼,把一個for each 循環+可變參數的小例子(JDK5)和大家分享一下
          ?1
          ?2public?class?VariableArgs?{
          ?3
          ?4????public?static?void?main(String[]?args)?{
          ?5????????VariableArgs?test?=?new?VariableArgs();
          ?6????????test.show("1","2");
          ?7????????test.show("1","hermit","3");
          ?8????????test.showObject(123,"hermit");
          ?9????????test.addT(1,2,3,4);
          10????}

          11????
          12????public?void?show(Stringstrings)?{
          13????????System.out.println(strings.length);
          14????????for(String?str?:?strings)?{
          15????????????System.out.print(str+"\t");
          16????????}

          17????????System.out.println();
          18????}

          19????
          20????public?void?showObject(Objectobjects)?{
          21????????System.out.println(objects.length);
          22????????for(Object?obj?:?objects)?{
          23????????????System.out.print(obj.toString()+"\t");
          24????????}

          25????????System.out.println();
          26????}

          27????
          28????public?void?addT(intobj)?{
          29????????System.out.println(obj.length);
          30????????int?rs?=?0;
          31????????for(int?x?:?obj)?{
          32????????????rs+=x;
          33????????}

          34????????System.out.println(rs);
          35????}

          36????
          37}

          38
          posted on 2006-12-22 11:08 交口稱贊 閱讀(2178) 評論(3)  編輯  收藏 所屬分類: java相關

          FeedBack:
          # re: for each 循環+可變參數的小例子(JDK5) 2006-12-22 15:17 javabeginer
          what use?  回復  更多評論
            
          # re: for each 循環+可變參數的小例子(JDK5) 2006-12-22 21:55 交口稱贊
          @javabeginer
          for each 循環很爽啊。可以少寫很多代碼。
          這個在項目中我已經大量使用了。


          可變參數可以動態處理一些東西。
          有機會我寫些例子。   回復  更多評論
            
          # re: for each 循環+可變參數的小例子(JDK5) 2006-12-24 18:21 孤枕
          不錯。學到了新東東。原來還有這么語法。  回復  更多評論
            
          主站蜘蛛池模板: 天气| 南皮县| 渭源县| 旬邑县| 锡林浩特市| 平昌县| 深州市| 泸溪县| 车致| 闻喜县| 泗水县| 阿瓦提县| 阿拉善盟| 黄浦区| 萨迦县| 苗栗市| 任丘市| 佛学| 嘉黎县| 台山市| 邢台市| 祁连县| 荣昌县| 西充县| 沁源县| 扶风县| 柘荣县| 台中县| 福清市| 杭锦后旗| 额济纳旗| 金堂县| 西乌| 广昌县| 广州市| 延庆县| 新沂市| 太湖县| 平乐县| 延安市| 吉木乃县|