Home » Core Java » LinkedList in Java

LinkedList in Java

LinkedList & its feature ::
1.  LinkedList class is an important class of Collection framework.
2.  LinkedList extends generic AbstractSequentialList.So the elements in LinkedList are stored in insertion order.
3.  LinkedList implements generic List, generic Deque, Cloneable and java.io.Serializable interface.
4.  LinkedList internally has a double LinkedList.Doubly LinkedList Node has three attributes generic item,addresee of previous node and address of next node.

5.  LinkedList is unsynchronized i.e. it is not thread safe.But, it can be made synchronized explicitly like below

5.  LinkedList can accept any element including multiple null values.
7.  LinkedList uses Iterator interface to traverse the elements.While traversing the elements using iterator if the      structure of the LinkedList is modified using add or remove method ,iterator will throw ConcurrentModificationException.So iterators for LinkedList are fail-fast.

Sample Program ::

Output ::

Now let us see an example of ConcurrentModificationException.In the below program while iterating the LinkedList,i am modifying the structure of the LinkedList by adding a new element.So I am getting ConcurrentModificationException.
Example of ConcurrentModificationException ::

Output ::


Leave a comment

Your email address will not be published. Required fields are marked *

4 × one =