Hi Mala,
Thanks for replying!
I have learned a lot by reading your book =)
I found another issue in page 260.
See what the books says:
Examine the definition of the following no-argument constructor defined in the class ArrayList.java:
However, the constructor code is:
Where DEFAULTCAPACITY_EMPTY_ELEMENTDATA is:
Thus, array list is created with size 0. The size is only increased to 10 when adding the first element. When adding the first element, the code will check the capacity. The argument to ensureCapacityInternal will be 1 (size 0 + 1). As the elementData is equals to DEFAULTCAPACITY_EMPTY_ELEMENTDATA, the capacity will be the greater value between 1 and default 10. So 10 will be the new size! See the code below.
ps: I'm using jdk1.8.0_121.
Regards,
Daniel Lobo