Thursday, April 5, 2012

Linkedlist vs Arraylist

LinkedList:
  • Each element/node in the LinkedList refers to its next element/node. 
  •  The elements in the LinkedList are accessed sequentially. i.e. the element at the specific index of the LinkedList cannot be accessed directly. 
  •  Insertion and deletion of the elements at any position in the LinkedList is preferment than ArrayList.
  • Random access of the elements in the LinkedList is not possible.
ArrayList:
  • Random access of the elements is possible. eg: the element at the index 5 can be accessed as list.get(5) where as in LinkedList it is not possible.
  • Insertion and deletion of the elements in the middle is not performant compared to LinkedList. In order to insert an element at some position, it shifts the elements to its right.


Use LinkedList, only if the requirement is to insert/delete elements in the middle of the List when iterating over the list. If not in most of the cases the ArrayList can be opted blindly.

The LinkedList data structure details can be found here

The restful web services tutorial can be found at restful web services tutorial
The hello world with Jersey can found hello world with Jersey 

No comments: