arraylist vs linkedlist

Post on 07-Jan-2016

212 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

ArrayList vs LinkedList

TRANSCRIPT

7/17/2019 ArrayList vs LinkedList

http://slidepdf.com/reader/full/arraylist-vs-linkedlist 1/2

7/17/2019 ArrayList vs LinkedList

http://slidepdf.com/reader/full/arraylist-vs-linkedlist 2/2

+here are few similarities between these classes which are as follows:

1. ,oth ArrayList and LinkedList are implementation of List interface.

". +hey both maintain the elements insertion order which means while

displaying ArrayList and LinkedList elements the result set would be having thesame order in which the elements got inserted into the List.

. ,oth these classes are non-synchronied and can be made synchronied

explicitly by using Collections.synchronizedList method.

*. +he iterator and list(terator returned by these classes are fail-fast #if list is

structurally modified at any time after the iterator is created/ in any way

except through the iterator&s own remove or add methods/ the iterator will

throw a ConcurrentModification!ce"tion).

#hen to use LinkedList and when to use ArrayList$

1) As explained above the insert and remove operations give good performance

#O(1)) in LinkedList compared to ArrayList#O(n)). 'ence if there is a

re!uirement of fre!uent addition and deletion in application then LinkedList is

a best choice.

") 0earch #get method) operations are fast in Arraylist #O(1)) but not in LinkedList

#O(n)) so (f there are less add and remove operations and more search operations

re!uirement/ ArrayList would be your best bet.

top related