When to use LinkedList over ArrayList in Java?

Technology CommunityCategory: JavaWhen to use LinkedList over ArrayList in Java?
VietMX Staff asked 3 years ago

LinkedList and ArrayList are two different implementations of the List interface. LinkedList implements it with a doubly-linked list.

  • LinkedList<E> allows for constant-time insertions or removals using iterators, but only sequential access of elements. In other words, you can walk the list forwards or backwards, but finding a position in the list takes time proportional to the size of the list.
  • ArrayList<E>, on the other hand, allow fast random read access, so you can grab any element in constant time. But adding or removing from anywhere but the end requires shifting all the latter elements over, either to make an opening or fill the gap.