離弦之Ray

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            55 Posts :: 0 Stories :: 33 Comments :: 0 Trackbacks
          一直疑惑 ArrayList<int> 怎么搞,但懶得去查,今天網上搜到了:

          The generics facility in Java can be used only for
          object (reference) types.  It cannot be used primitive
          types like 'int' or 'float'.

          So, if you wanted an ArrayList that contained only
          integer data, then you'd need to use the object type
          which corresponds to int: java.lang.Integer.

             ArrayList<Integer> numbers;
             numbers = new ArrayList<Integer>(40);

          Fortunately, the new Autobox/unbox features of Java can
          make this work just like an ArrayList of int.

             numbers.add(27);

          The value 27 will be automatically boxed as an Integer
          object, then added to the ArrayList<Integer>.

          For more information, consult
          http://java.sun.com/developer/technicalArticles/J2SE/generics/index.html
          http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

          posted on 2007-12-23 15:22 離弦之ray的技術天空 閱讀(935) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 永城市| 西林县| 定襄县| 邢台县| 乐平市| 榆林市| 鲁甸县| 甘南县| 西乌珠穆沁旗| 吐鲁番市| 微博| 广安市| 嘉荫县| 体育| 万源市| 宁化县| 耿马| 湘乡市| 浑源县| 南郑县| 徐汇区| 汉中市| 高淳县| 凤山县| 三河市| 隆回县| 平武县| 天镇县| 长兴县| 丁青县| 秦安县| 湟中县| 新闻| 措美县| 康乐县| 雷山县| 菏泽市| 甘南县| 凤庆县| 化州市| 东宁县|