LinkedLists are a part of the Collection Framework offered by Java as a part of the java.util package. Collections are data structures which can be used to hold a group of objects together as a single entity and perform operations on top. They are also provided with powerful and useful methods and features which can reduce the overall programming effort.
- LinkedList is implemented using Doubly-linked list. It implements java.util.List and Deque interfaces.
- A linked list is a data structure consisting of a group of nodes which together represent a sequence.
- Under the simplest form, each node is composed of a data and a reference (in other words, a link) to the next node in the sequence in java.
- LinkedList extends AbstractSequentialList (abstract class), AbstractSequentialList extends AbstractList in java.
Constructors for Java LinkedList:
- LinkedList(): This is default constructor of linked list.
- LinkedList(Collection C): This constructor will add existing collection object to linked list.
Features of LinkedList:
- Duplicate elements – LinkedList allows to store duplicate elements in java.
- Null elements -Null elements can be added in LinkedList in java.
- Insertion order – LinkedList maintains insertion order if all elements are added using add or addLast method because both method adds elements add element at end of LinkedList.
- Asynchronous – It is not synchronized (because 2 threads on same LinkedList object can access it at same time) in java.
- Performance – LinkedList is not synchronized, hence its operations are faster as compared to some other synchronized implementation of List interface in java.