Java dynamic array sizes?

前端 未结 18 2170
星月不相逢
星月不相逢 2020-11-22 04:37

I have a class - xClass, that I want to load into an array of xClass so I the declaration:

xClass mysclass[] = new xClass[10];
myclass[0] = new xClass();
my         


        
18条回答
  •  太阳男子
    2020-11-22 05:17

    I recommend using vectors instead. Very easy to use and has many predefined methods for implementation.

    import java.util.*;
    
    Vector v=new Vector(5,2);
    

    to add an element simply use:

    v.addElement(int);
    

    In the (5,2) the first 5 is the initial size of the vector. If you exceed the initial size,the vector will grow by 2 places. If it exceeds again, then it will again increase by 2 places and so on.

提交回复
热议问题