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

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

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

    sunfruit[請(qǐng)?jiān)L問(wèn)http://www.fruitres.cn]

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

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

        --sunfruit

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


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

     /**
      * 計(jì)數(shù)器(數(shù)組長(zhǎng)度)
      */
     private int size_count;

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

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

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

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

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

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

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

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

     /**
      * 刪除數(shù)據(jù)
      * @param j int 一個(gè)要?jiǎng)h除的整數(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 一個(gè)要?jiǎng)h除的索引        
      */
     public void removeIndex(int j) {
      if (j < 0 || j >= size_count) {
       throw new IndexOutOfBoundsException("超出最大或最小索引值,無(wú)法刪除數(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ù)組長(zhǎng)度
      */
     public int getSize() {
      return size_count;
     }

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

     /**
      * 獲得數(shù)組對(duì)象,String格式
      * @return String[] 獲得數(shù)組的對(duì)象
      */
     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;
     }

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

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

    主站蜘蛛池模板: 免费观看一区二区三区| 亚洲狠狠久久综合一区77777| 中文字幕亚洲免费无线观看日本| 国产精品亚洲一区二区在线观看| 亚洲性无码av在线| 国产亚洲综合视频| 亚洲精品亚洲人成在线观看麻豆 | 亚洲一区AV无码少妇电影☆| 成年女人午夜毛片免费看| 免费A级毛片无码A∨| 精品熟女少妇aⅴ免费久久| 毛片亚洲AV无码精品国产午夜| 亚洲男女一区二区三区| 亚洲无码在线播放| 亚洲精品高清在线| 免费大黄网站在线看| 免费黄色app网站| 青娱乐免费视频在线观看| 3344永久在线观看视频免费首页 | 亚洲精品乱码久久久久66| 国产成人精品高清免费| 大香人蕉免费视频75| 大学生一级毛片免费看| 91福利免费体验区观看区| 久久久久久成人毛片免费看| 国色精品va在线观看免费视频| 国产日韩一区二区三免费高清| 9久久免费国产精品特黄| 国产vA免费精品高清在线观看| 永久免费无码日韩视频| 一级人做人a爰免费视频| 亚洲国产免费综合| 国产免费久久精品99久久| 中文字幕乱码系列免费| 抽搐一进一出gif免费视频| 91免费在线视频| 18禁在线无遮挡免费观看网站| 免费看黄的成人APP| 在线观看免费av网站| 日本三级2019在线观看免费| 搡女人免费视频大全|