Java dynamic array sizes?

前端 未结 18 2471
星月不相逢
星月不相逢 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:13

    Where you declare the myclass[] array as :

    xClass myclass[] = new xClass[10]
    

    , simply pass in as an argument the number of XClass elements you'll need. At that point do you know how many you will need? By declaring the array as having 10 elements, you are not declaring 10 XClass objects, you're simply creating an array with 10 elements of type xClass.

提交回复
热议问题