Skip to main content

Posts

Showing posts from July, 2011

Difference between ArrayList and LinkedList

What is the difference between ArrayList and LinkedList

First of all lets see what Interfaces they implement.
ArrayList (See on Oracle/sun site)SerializableCloneableIterable<E>Collection<E>List<E>RandomAccessLinkedList(See on Oracle/Sun site)SerializableCloneableIterable<E>Collection<E>Deque<E>List<E>Queue<E>By looking at interface being implemented by these two collection, we could see RandomAccess is implemented by ArrayList and Queue<E>,Deque<E> implemented by LinkedList only. So all the differences between these two collections are because of these three Interfaces and their implementation.

RandomAccess : ArrayList can be accessed randomly, means we could access nth element of an ArrayList directly without affecting search/seek performance. e.g. list.get(n). Means get performance of nth element will never depend on how large is the ArrayList.It will remain constant.
While LinkedList cant be accessed randomly(though it does …