ArrayList
ArrayList<T> is a dynamically growing ordered collection where elements are accessed by index. It supports inserting, modifying, and deleting elements at any position.
Unlike Array, an ArrayList can change size at runtime, making it suitable for scenarios with frequent element additions and removals. Use add to append elements at the end, add(value, at: index) to insert at a specific position, and remove(at: index) to delete elements.
The code on the right demonstrates core operations of ArrayList: creating an empty list, adding elements, inserting at a specific position, reading and modifying by index, deleting elements, and iterating through all elements.
ArrayList is a reference type; assignment does not create a copy, and multiple references share the same data.Try modifying the code: change the insertion position to 0 and see how the output changes.