posts - 75,comments - 83,trackbacks - 0
          posted @ 2008-07-23 22:18 梓楓 閱讀(670) | 評(píng)論 (0)編輯 收藏
          posted @ 2008-07-22 16:31 梓楓 閱讀(3571) | 評(píng)論 (5)編輯 收藏
               摘要: 增強(qiáng)的for循環(huán)
             為了迭代集合和數(shù)組,增強(qiáng)的for循環(huán)提供了一個(gè)簡(jiǎn)單、兼容的語法。有兩點(diǎn)值得一提:   Init表達(dá)式

            在循環(huán)中,初始化表達(dá)式只計(jì)算一次。這意味著您通常可以移除一個(gè)變量聲明。在這個(gè)例子中,我們必須創(chuàng)建一個(gè)整型數(shù)組來保存computeNumbers()的結(jié)果,以防止每一次循環(huán)都重新計(jì)算該方法。您可以看到,下面的代碼要比上面的代碼整潔一些,并且沒有泄露變量numbers:

            未增強(qiáng)的For:  int sum = 0;  Integer[] numbers = computeNumbers();  for (int i=0; i < numbers.length ; i++) sum += numbers[i];   增強(qiáng)后的For:    int sum = 0;  for ( int number: computeNumbers() ) sum += number;......
            閱讀全文
          posted @ 2008-07-21 23:01 梓楓 閱讀(263) | 評(píng)論 (0)編輯 收藏
          posted @ 2008-07-21 14:09 梓楓 閱讀(2295) | 評(píng)論 (1)編輯 收藏
          posted @ 2008-07-20 22:14 梓楓 閱讀(3400) | 評(píng)論 (2)編輯 收藏
          posted @ 2008-07-14 15:42 梓楓 閱讀(756) | 評(píng)論 (0)編輯 收藏
          posted @ 2008-06-30 15:37 梓楓 閱讀(5194) | 評(píng)論 (12)編輯 收藏
          posted @ 2008-06-30 15:14 梓楓 閱讀(37397) | 評(píng)論 (6)編輯 收藏
          posted @ 2008-06-30 10:36 梓楓 閱讀(498) | 評(píng)論 (0)編輯 收藏
          posted @ 2008-06-12 15:27 梓楓 閱讀(1692) | 評(píng)論 (0)編輯 收藏
          posted @ 2008-05-19 16:37 梓楓 閱讀(5580) | 評(píng)論 (2)編輯 收藏
          posted @ 2008-05-19 15:53 梓楓 閱讀(206) | 評(píng)論 (0)編輯 收藏
          posted @ 2008-05-06 17:05 梓楓 閱讀(1982) | 評(píng)論 (1)編輯 收藏
          posted @ 2008-04-19 16:59 梓楓 閱讀(421) | 評(píng)論 (0)編輯 收藏
          posted @ 2008-04-18 20:35 梓楓 閱讀(297) | 評(píng)論 (0)編輯 收藏
          posted @ 2008-04-17 20:15 梓楓 閱讀(448) | 評(píng)論 (0)編輯 收藏
          posted @ 2008-04-17 19:27 梓楓 閱讀(1837) | 評(píng)論 (0)編輯 收藏
          posted @ 2008-04-17 13:56 梓楓 閱讀(737) | 評(píng)論 (0)編輯 收藏
          posted @ 2008-03-31 15:27 梓楓 閱讀(9677) | 評(píng)論 (9)編輯 收藏
          posted @ 2008-03-25 10:54 梓楓 閱讀(311) | 評(píng)論 (0)編輯 收藏
          列出全部?jī)?nèi)容
          共4頁(yè): 上一頁(yè) 1 2 3 4 下一頁(yè) 
          主站蜘蛛池模板: 荥经县| 石台县| 麻栗坡县| 鲁山县| 古田县| 栾川县| 晋城| 乾安县| 荔浦县| 平泉县| 芒康县| 五原县| 虎林市| 永福县| 富源县| 秦皇岛市| 文成县| 彭州市| 九龙坡区| 十堰市| 江西省| 平泉县| 留坝县| 江门市| 溧水县| 马公市| 静宁县| 江津市| 灵丘县| 来宾市| 耿马| 济源市| 静宁县| 舞阳县| 新和县| 塔河县| 巴东县| 郧西县| 吴堡县| 呼图壁县| 宜春市|