Linked Lists and Arrays can be used for storing a list of data.
Arrays are allocated continuous memory locations and the array name holds a reference to the beginning of this memory block. Individual elements can be located easily, randomly and in constant time by calculating the exact memory location of the element using the start memory location of the allocated block and the position (index) of the element.
Linked lists however are not allocated with fixed continuous memory locations. In a linked list nodes are allocated in different memory locations and each node points (contains the address of) the next node in the list. Last node does not point to anything. Both arrays and linked lists have their advantages and disadvantages.
Advantages of arrays
- Simple and easy to use
- Faster constant time access to the elements.
Disadvantages of arrays
- Fixed Size
- Complex position based insertion
- To insert an element at a given position we might have to shift the remaining elements to its right.
Advantages of linked lists:
- They can be expanded in constant time. Insertions and deletions will be faster.
- No wastage of space, except the space used for pointers. We can start with space for just one element allocated and add on new elements easily.
Disadvantages of linked lists
- Array support random-access and it takes only 0(1) to access any element in the array. In linked lists we need to traverse the list to reach the required node and hence take 0(n) in worst case.
- Overhead of storing and retrieving data.
You can learn about arrays in Java at javajee.com/introduction-to-arrays-in-java