Java Collections: LinkedList vs ArrrayList
Oracle Corporation

Java Collections: LinkedList vs ArrrayList

One of the most important functionalities in Java programming is the ability to manage, store, retrieve, and sort data. Since data comes in many forms and styles, it is absolutely necessary to have classes capable of utilizing data presented to it. Generic methods such as those provided by the Collections library  allow for objects of any type to be stored in a list for easy management. One of the problems presented to the developer using the Collections library is the dilemma of which generic list to use.

LinkedList utilizes a system of nodes to store data. Node are independent objects that store both the object injected into the list and a pointer to the next object in the series. Node structure has several advantages. For instance, if adding to the list, there is no need to re-size the entire previous list. Depending on implementation, adding and removing objects from a LinkedList tends to have a much lower runtime complexity than ArrayLists. 

ArrayLists are much more intuitive than LinkedLists. ArrayLists implement a simple array that functions very much like traditional arrays. The advantage over traditional arrays is the dynamic size. Traditional arrays must have methods implemented to handle re-size actions. However, ArrayLists have these methods implemented already, and are much faster to implement in code. The real advantage of ArrayLists lies in random access tasks. If objects at various indexes must be retrieved, the array structure of an ArrayList allows for a runtime complexity of big O of 1. This is the most optimized complexity possible in any program. 

When choosing which list style to implement, some important things to consider are frequency of adding and removing, frequency of re-sizing, and need for accessing random points in the list. For tasks involving plenty of random accessing, an ArrayList is usually the best option. For more "cold storage" needs, LinkedLists provide the most optimized structure. In general, both lists will work fine and interchangeably for storage tasks, but poor choice in lists may result in noticeably increasing runtime. 

This is an article from Javarevisited that is very helpful in explaining more: http://javarevisited.blogspot.com/2012/02/difference-between-linkedlist-vs.html

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics