7
Similarities between ArrayList and LinkedList

Similarities between ArrayList and LinkedList

Embed Size (px)

Citation preview

Page 1: Similarities between ArrayList and LinkedList

Similarities between ArrayList and

LinkedList

Page 2: Similarities between ArrayList and LinkedList

1. Insertion Order.• The List<E> interface’s add(E e) method defines a contract that specified elements must be appended to the list. 

• As ArrayList and LinkedList are concrete implementations of List interface they follow the contract and hence insertion order of element is preserved.

Page 3: Similarities between ArrayList and LinkedList

2. Clone.• clone() operations of ArrayList<E> as well as LinkedList<E> returns the shallow copy of elements. This means elements are not itself copied or backup.

Page 4: Similarities between ArrayList and LinkedList

3. Synchronization.• ArrayList<E> and LinkedList<E> both of them are non-synchronized collection. They can be synchronized by using Collections.synchronizedList() method of Collections class. 

• All methods are synchronized except iterator(), listIterator() and listIterator(int index).

Page 5: Similarities between ArrayList and LinkedList

4. Iterator.• The iterators used in ArrayList<E> and LinkedList<E> are fail fast. Fail fast iterators throws ConcurrentModificationException.

Page 6: Similarities between ArrayList and LinkedList

5. Implementation of?• Both ArrayList<E> and LinkedList<E> are implementations of List<E> interface.

• ArrayList class provides Random Access to elements where LinkedList provides sequential access.

Page 7: Similarities between ArrayList and LinkedList

That’s all folks.