If I have a say A class, and I declare an array of 10 elements of this class, like
A [] arr=new A[10];
Then, 10 new A. objects are created and stored in the array.
However, I would like to do something in the lines A arr[10];where the array just contains references to null objects.
The reason I need this is because I only need an array to store the instances that I populate later in the code. Thus, the objects created above are still lost, and, as I understand it, creating an object is expensive.
So, is there a way to have an array of links that I can point to objects that I need later? Or is it impossible, and should I resort to use ArrayList?
Akash source
share