InterviewSolution
| 1. |
How Arraylist Works Internally In Java? |
|
Answer» Basic data structure USED by ARRAYLIST to store objects is an array of Object class, which is defined like - transient Object[] elementData; When we ADD an element to an ArrayList it first verifies whether it has that much capacity in the array to store new element or not, in case there is not then the new capacity is CALCULATED which is 50% more than the old capacity and the array is increased by that much capacity (Actually uses Arrays.copyOf which returns the original array increased to the new length) Basic data structure used by ArrayList to store objects is an array of Object class, which is defined like - transient Object[] elementData; When we add an element to an ArrayList it first verifies whether it has that much capacity in the array to store new element or not, in case there is not then the new capacity is calculated which is 50% more than the old capacity and the array is increased by that much capacity (Actually uses Arrays.copyOf which returns the original array increased to the new length) |
|