When the internal array becomes full, ArrayList creates a larger array, copies the existing elements, and continues adding. Important complexities: get() → O(1) add() at end → O (1) amortized ...
This is a Java 17 desktop application for Eclipse. It is not a browser website. The project uses Swing for the interface, JDBC for database access, and PostgreSQL for persistent records.
一、ArrayList 的优势来自连续存储 ArrayList 底层使用可扩容数组。它通过下标访问元素时可以直接计算地址,因此 get (index) 的时间复杂度是 O (1)。尾部追加通常也是摊销 O (1),但扩容时会创建更大的数组并复制旧元素,因此一次扩容可能产生明显的瞬时开销。
数据结构中的线性表,常以顺序存储方式实现,即用连续内存保存序列中的元素,这种结构被称为顺序表。基于数组构建的顺序表,通过地址计算可让随机访问达到 O(1),兼顾了内存局部性与读取效率。但固定容量的数组无法动态增长,因此需要设计扩容策略。Java 中的 ArrayList 就是顺序表思想的经典 ...