Java的数组不支持动态改变维数,你可以重新声明一个新数组并冲掉原来的。或者干脆用ArrayList之类的东西代替。

解决方案 »

  1.   

    用Vector类,动态添加,最后trim()一下;并调用它的toArry方法、转换成数组
      

  2.   


    使用vector对象阿这个东西正好适合你的这种情况阿
    具体用法见《thinking in java》/*--by bookbobby(书呆)-+
     |            |
     |  你说爱我只是习惯  |
     |  再也不是喜欢    |
     |  我给你的爱     |
     |  已不再温暖     |
     |            |
     +--by bookbobby(书呆)-*/
      

  3.   

    Collection Interface.
    it has got two kind of implementations.
    List
    Set
    If you want a dictionary structure, Map is good to you.
    But all of them are special for object only, if you have got primitive (int, byte), you have got to transfer it.
      

  4.   

     int[] a = new int[1];
     for ( int i = 0; i < 100; i++ ) {
         if ( i >= a.length ) {
    int[] b = new int[i+1];
    System.arraycopy(a,0,b,0,a.length);
    a = b;
         }
         a[i] = i;
     }
    不过,每次加1,性能不好,尤其是对于比较大的数组
    最好还是采用Vector的增长策略,每次加倍 int[] b = new int[i*2];