-
Array of objects
i am writing a code for workers in inheritance .
there is nothing wrong with code but i have a question..
if i have 8 workers i will create an array of 8 objects:
worker[] object = new worker[8];
My question here ..
if i don't know the number of workers what i will do ??
and thanks in advance.
-
Re: Array of objects
Use an ArrayList.
If you must use arrays, create one of a reasonable size. When it gets full, create another larger array and copy the contents of the first array to the new one and set the array variable to refer to the new array.
-
Re: Array of objects
Norm has it right on this one. You may and is highly recommended to use ArrayLists. I can not remember the last time I just used an array. ArrayLists can store vast amount of information and will double in size every time the AL is forced to allocate memory. It is also easier to sort and AL rather than an array.