I want to ask a question about Java. I have a user-defined object class, student, which have 2 data members, name and id. And in another class, I have to declare that object[], (e.g. student stu[?];). However, I don't know the size of the object array. Is it possible to declare an object array but don't know the size? thank you.
解决方案
User ArrayList instead. It'll expand automatically as you add new elements. Later you can convert it to array, if you need.
As another option (not sure what exactly you want), you can declare Object[] field and not initialize it immediately.