Nuacht

Learn how to use lazy instantiation and eager instantiation in your Java programs. Which approach is better? It depends on the scenario.
As the comments indicate, size keeps track of how many elements are in MyArrayList, and array is the array that actually contains the elements. The constructor creates an array of 10 elements, which ...
The constructor creates an array of 10 elements, which are initially null, and sets size to 0. Most of the time, the length of the array is bigger than size, so there are unused slots in the array.