Java dynamic array sizes?

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

    As other users say, you probably need an implementation of java.util.List.

    If, for some reason, you finally need an array, you can do two things:

    • Use a List and then convert it to an array with myList.toArray()

    • Use an array of certain size. If you need more or less size, you can modify it with java.util.Arrays methods.

    Best solution will depend on your problem ;)

提交回复
热议问题