Use Object[]
to store data. ArrayList is not thread-safe, while Vector is thread-safe.
Thread safety
Both are not synchronized ↔ not thread-safe.
Bottom data structure
ArrayList uses an Object
array, while LinkedList uses a bi-directional LinkedList
data structure.
add(E e)
method, ArrayList appends the specified element to the end of this list by default, which is O(1). However, if you insert and delete elements at the specified position i (add(int index, E element)
), the time complexity is O(n-i), because the (n-i) elements after the i and i elements move one bit back /forward.add(E e)
method, the time complexity is similar to O(1). If you insert and delete elements at the specified position i (add(int index, E element)
), the time complexity is approximately O(n) because it needs to be moved to the specified position before inserted.Random access
LinkedList does not support random element access, while ArrayList supports it.
Memory space occupancy
ArrayList reserves a certain capacity of space at the end of the list, while LinkedList’s each element needs to consume more space, because next
, pre
and data are stored.