Saturday 15 June 2013

ArrayList vs LinkedList in Java

1) Both ArrayList and LinkedList are implementation of List interface, which means you can pass either ArrayList or LinkedList if a method accepts Listinterface.

2) Both ArrayList and LinkedList are not synchronized, which means you can not shared them between multiple threads without external synchronization.

3) ArrayList and LinkedList are ordered collection e.g. they maintain insertion order of elements i.e. first element will be added on first position.

4) ArrayList and LinkedList also allows duplicates and null unlike any other List implementation e.g. Vector.

5) Iterator of both LinkedList and ArrayList are fail-fast which means they will throw ConcurrentModificationExceptionif collection is modified structurally once Iterator is created. They  are different than CopyOnWriteArrayList whose Iterator is fail-safe.

No comments:

Post a Comment