離弦之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的技術天空 閱讀(940) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 奈曼旗| 肃宁县| 沭阳县| 萨嘎县| 开阳县| 莱阳市| 新和县| 阿勒泰市| 平江县| 石棉县| 图木舒克市| 平舆县| 南华县| 拉孜县| 色达县| 九寨沟县| 泸西县| 神农架林区| 莒南县| 松阳县| 观塘区| 九寨沟县| 安龙县| 杭锦后旗| 扬中市| 曲靖市| 大安市| 九龙坡区| 万宁市| 财经| 中方县| 安塞县| 洪湖市| 定结县| 麦盖提县| 涪陵区| 洱源县| 大关县| 伊吾县| 阿荣旗| 二连浩特市|