LinkedList: Introduction
Let's see how LinkedList works in Java.
We'll cover the following...
The LinkedList class in Java implements the List and the Deque interface. Some of the salient features of a LinkedList are:
-
The elements are inserted in the order of insertion.
-
It supports duplicate elements.
-
We can add any number of null elements.
Internal implementation of LinkedList
The LinkedList class has a static inner class called Node
. This class contains three fields:
item
- This contains the value of the current element.
next
- This contains the pointer to the next element.
prev
- This contains the pointer to the previous element.
Below is the code for the Node
class.