How Java ArrayList Works
ArrayList is implemented based on arrays, using an array to store elements and dynamically adjusting the size of the array as needed. When the array is full, ArrayList creates a new array, copies the elements from the original array to the new one, and continues adding new elements.
When initialized, an ArrayList will create an array with an initial capacity of 10. If the array is full when adding elements to the ArrayList, a new array will be created using the System.arraycopy() method, and the elements from the original array will be copied to the new array.
ArrayList also supports random access as it is implemented based on arrays, allowing direct access to elements in the array based on their index.
In essence, the underlying principle of ArrayList is primarily based on arrays, and it achieves dynamic element addition by dynamically adjusting the size of the array.