<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    sunfruit[請訪問http://www.fruitres.cn]

    --我相信JAVA能走得更遠(yuǎn) QQ:316228067

    [原創(chuàng)]用JAVA寫的整形動態(tài)數(shù)組

        --sunfruit

        用java實現(xiàn)了整形數(shù)字的動態(tài)數(shù)組


    JDK版本
            1.3.1
        功能
            實現(xiàn)了添加整數(shù)到動態(tài)數(shù)組中,JDK(1.5以下)不提供整形類型的集合,比如ArrayList這樣的集合不允許添加整數(shù),
            但是在編程過程中會遇到需要整形的動態(tài)數(shù)組的情況,所以這個類實現(xiàn)了這樣的功能
           
        歡迎大家提意見,交流
       
        代碼如下:
    /**
     * Title: 整形動態(tài)數(shù)組
     * Description: 實現(xiàn)了整形數(shù)字的動態(tài)添加
     * Copyright: Copyright (c) 2003
     * Company: LingTu
     * @author cuijiang
     * @version 2.0
     */
    public class DynArrayInt {
     /**
      * 原始數(shù)組
      */
     private int[] data_All;

     /**
      * 計數(shù)器(數(shù)組長度)
      */
     private int size_count;

     /**
      * 構(gòu)造器,初始長度默認(rèn)為10
      */
     public DynArrayInt() {
      this(10);
     }

     /**
      * 構(gòu)造器,設(shè)置數(shù)組的初始長度
      *
      * @param iniSize  int 數(shù)組的初始長度
      */
     public DynArrayInt(int iniSize) {
      data_All = new int[iniSize];
     }

     /**
      * 添加數(shù)據(jù),調(diào)用checkAdd(int i)
      * @param i   int 一個整形數(shù)字
      */
     public void addInt(int i) {
      //判斷是否增長
      this.checkAdd(size_count + 1);
      //賦值
      data_All[size_count++] = i;
      //添加時數(shù)組長度加一
     }

     /**
      * 添加數(shù)字,判斷是否增長
      * @param i   int 一個整形數(shù)字
      */
     private void checkAdd(int i) {
      //獲得原來的大小
      int star = data_All.length;
      //判斷是否增長
      if (i > star) {
       int starData[] = data_All;
       //設(shè)定增長大小
       int endall = star * 2;
       data_All = new int[endall];
       System.arraycopy(starData, 0, data_All, 0, size_count);
      }
     }

     /**
      * 獲取數(shù)據(jù)
      * @param i    int 索引號
      * @return int
      */
     public int getInt(int i) {

      if (i < 0 || i >= size_count) {
       throw new IndexOutOfBoundsException("超出最大或最小索引值,無法取得數(shù)據(jù)");
      } else {
       return data_All[i];
      }
     }

     /**
      * 獲取數(shù)據(jù)轉(zhuǎn)換成字符串模式
      * @param i  int 索引號
      * @return String
      */
     public String getIntToString(int i) {

      if (i < 0 || i >= size_count) {
       throw new IndexOutOfBoundsException("超出最大或最小索引值,無法取得數(shù)據(jù)");
      } else {
       return String.valueOf(data_All[i]);
      }
     }

     /**
      * 刪除數(shù)據(jù)
      * @param j int 一個要刪除的整數(shù)        
      */
     public void remove(int j) {
      for (int i = 0; i < size_count; i++) {
       if (data_All[i] == j) {
        System.arraycopy(data_All, i+1, data_All, i, size_count-i-1); // 復(fù)制數(shù)據(jù)
        --size_count;
        return;
       }
      }
     }

     /**
      * 刪除數(shù)據(jù)
      * @param j int 一個要刪除的索引        
      */
     public void removeIndex(int j) {
      if (j < 0 || j >= size_count) {
       throw new IndexOutOfBoundsException("超出最大或最小索引值,無法刪除數(shù)據(jù)");
      } else {
       System.arraycopy(data_All, j + 1, data_All, j, size_count -j- 1); // 復(fù)制數(shù)據(jù)
       --size_count;
       return;
      }
     }

     /**
      * 獲取大小
      * @return int 獲得數(shù)組長度
      */
     public int getSize() {
      return size_count;
     }

     /**
      * 獲取數(shù)組對象
      * @return int[] 獲得數(shù)組對象
      */
     public int[] getAllInt() {
      int[] starData = new int[size_count];
      System.arraycopy(data_All, 0, starData, 0, size_count);
      return starData;
     }

     /**
      * 獲得數(shù)組對象,String格式
      * @return String[] 獲得數(shù)組的對象
      */
     public String[] getAllIntToString() {
      int[] tempint = getAllInt();
      String[] starData = new String[tempint.length];
      for (int i = 0; i < starData.length; i++) {
       starData[i] = String.valueOf(tempint[i]);
      }
      return starData;
     }

     /**
      * 刪除全部內(nèi)容
      */
     public void removeAll() {
      data_All = new int[10];
      size_count = 0;
     }
    }

    posted on 2006-02-19 17:33 sunfruit 閱讀(1418) 評論(0)  編輯  收藏 所屬分類: JAVA SE & EE

    主站蜘蛛池模板: 亚洲日本VA午夜在线电影| 久久精品国产亚洲av水果派| 亚洲一级片在线观看| 亚洲a一级免费视频| 亚洲高清在线观看| 无码囯产精品一区二区免费 | 四虎影视永久免费观看| 亚洲影院天堂中文av色| 日韩免费视频网站| 老司机午夜性生免费福利 | 亚洲一区在线免费观看| 麻豆一区二区免费播放网站 | 91精品成人免费国产片| 亚洲国产精品人久久电影| 97在线线免费观看视频在线观看| 一本色道久久88—综合亚洲精品| 国产老女人精品免费视频| 免费看内射乌克兰女| 亚洲精品无码久久久久sm| 18以下岁毛片在免费播放| 亚洲私人无码综合久久网| 无码不卡亚洲成?人片| 中国一级特黄的片子免费| 亚洲五月六月丁香激情| 我要看免费的毛片| sss在线观看免费高清| 亚洲自偷自偷精品| 日本高清免费中文字幕不卡| 中文字字幕在线高清免费电影| 内射干少妇亚洲69XXX| 日本无吗免费一二区| AAAAA级少妇高潮大片免费看| 亚洲黄色免费网站| 免费国产不卡午夜福在线| 四虎国产精品永久免费网址| 一区二区亚洲精品精华液| 亚洲国产成人一区二区精品区| 中文字幕人成无码免费视频| 一区二区三区在线观看免费| 亚洲另类精品xxxx人妖| 不卡一卡二卡三亚洲|