Array list and linked list both implements list interface. ArrayList is more popular amongst programmer.The main difference between Arraylist and Linked list is arraylist implemented using re sizable array while linkedlist is implemented using doubly linked list.
ArrayList | LinkedList |
Arraylist is an index based data structure.Array provides O(1) performance for get(index) method but remove is costly in ArrayList as you need to rearrange all elements. | LinkedList doesn't provide Random or index based access and you need to iterate over linked list to retrieve any element which is of order O(n). |
In case of arraylist for updating the list anywhere other than end of the list need re-indexing of the list. | Insertion are easy and fast in linked list because there is no risk of resizing the data and copying the data into new array. |
ArrayList only have the data object | Linked list has both data and address to the next link.Hence linked list has more memory overhead |
When to use LinkedList
Use it when your application is more insertion and removal dependent. i.e if the insertion and removal operation is more frequent operation than the retrieval of the data.
When to use Arraylist
Use ArrayList in Java for all there situation where you need a non-synchronized index based access. ArrayList is fast and easy to use, just try to minimize array resizing by constructing arraylist with proper initial size.
You might also like :
Difference between getAttribute and getParameter
Comments
Post a Comment
.