Updates
  • Starting New Weekday Batch for Full Stack Java Development on 27 September 2025 @ 03:00 PM to 06:00 PM
  • Starting New Weekday Batch for MERN Stack Development on 29 September 2025 @ 04:00 PM to 06:00 PM
Join Course

Introduction of Linked List Data Structure

In this article, we will learn about one of the most important linear data structures, the Linked List. In this tutorial, we will understand how the Linked List stores and manages its data. Additionally, we will cover a crucial aspect: when and where we can effectively use the Linked List in application development.

What is a Linked List Data Structure?

• A Linked List is a linear data structure, similar to an array.
• It stores data using nodes.
• Each node is a memory allocation that holds the data and the address or reference (in Java) of the next node in the list.

Linked List Introduction
class Node{
	int data;
	Node next;
}
class JTC{
	public static void main(String arg[]){
		Node n1 = new Node(); // first node.
		Node n2 = new Node(); // second node.

		n1.data = 101; // storing 101 into data-part of the first node [n1].
		n1.next = n2;  // storing the referecne of the second node [n2] into the next-part of the first node [n1].

		n2.data = 202; // storing 202 into the data-part of the second node [n2]. 
		n2.next = null;// storing the null into the next-part of the second node [n2] because there is no node after the n2.
	}
}
Linked List Introduction

In this example, we define the Node class to represent the node structure. We create two nodes, n1 and n2. As shown, the Node class contains two instance variables: int data and Node next. Each time we create an object of the Node class (i.e., a node), separate memory allocations are made for the data and next variables for each object or node.
int data: This variable represents the data part of the node, which stores an integer value.
Node next: This variable holds the reference to the next node in the list.
In the next section of the example, we have a class JTC with a main method. Inside the main method, we create two objects of the Node class:
Node n1 = new Node();
Node n2 = new Node();
These represent two different nodes. As we discussed, the data part stores the value, and the next part holds the reference to the next node.
In the code, we assign values as follows:
n1.data = 101;
n1.next = n2;
n2.data = 202;
n2.next = null; // n2.next = null because n2 is the last node.
This sets up a linked list where n1 holds the data 101 and references n2, which holds the data 202. Since n2 is the last node, its next reference is null.

The first node is called the HEAD, and the last node is called the TAIL.
Since the Linked List Data Structure doesn’t use index-based representation, we cannot access elements randomly; we must traverse the list sequentially.
The Linked List is a dynamic linear data structure because we can easily add or remove nodes at runtime, allowing it to grow or shrink as needed.

class LinkedList{

Node head; // It points to the first node of a Linked-List.

// Node class representing the Node Category.
private class Node{
    int data; // It is the data-part of a node.
    Node next; // it is the next-part of a node.
}

// create () is dedicated to create a node and add into the linked list. 
void create(int data){
    if(head == null){
        Node n1 = new Node(); // Creating new Node.
        n1.data = data; // Storing Data into the data-part into newly created node.
        n1.next = null;
        head = n1;
    }else{
        Node temp_node = head;
        // Searching for last node.
        while(temp_node.next != null){
            temp_node = temp_node.next;
        } 
        Node n1 = new Node(); // Creating new node.
        n1.data = data;
        n1.next  = null;
        temp_node.next = n1; // Storing the reference of newly created node into next-part of the last node. 
    }
}

// print() is dedicated to traverse the Linked List from HEAD to TAIL and print the element. 
void print(){
    System.out.print("Linked-List is :- ");
    // Traversing the linked list till the last node.
    while(head != null){
        System.out.print(head.data+" ");
        head = head.next;
    }
}
}
class JTC{
public static void main(String arg[]){
    LinkedList l1 = new LinkedList(); // Creating a Linked List.
    // Creating Nodes and adding into the linked list.
    l1.create(101);
    l1.create(102);
    l1.create(103);
    l1.create(104);
    l1.create(105);
    // Printing the elements of the Node.
    l1.print();
}
}
        Linked-List is :- 101 102 103 104 105
Linked List Introduction

In the above example, we work with a simple linked list to understand how it stores elements using nodes and how we can access the data through the next node's reference.
We have a class LinkedList that represents the linked list. Inside this class, there is an inner class Node that represents each node. The Node class is an inner class because other classes cannot access it directly.
In the LinkedList class, we define a method void create(int data) which is responsible for creating a Node object and storing the given data in the node’s data part.
The method first checks if the head reference variable is null. If it is null, it means the list is empty, so we create a new node and store its reference in the head variable.

if (head == null) { 
    Node n1 = new Node(); 
    n1.data = data; 
    n1.next = null; 
    head = n1; 
} 

This assigns the first node as the head of the list.

Otherwise, if the head is not null, we search for the last node in the current linked list and then create a new node, storing the given data in the new node's data part:

else { 
    Node temp_node = head; 
    while (temp_node.next != null) { 
        temp_node = temp_node.next; 
} 
    Node n1 = new Node(); 
    n1.data = data; 
    n1.next = null; 
       temp_node.next = n1; 
} 

There is another method in the LinkedList class called void print(), which is responsible for printing the data from the head node to the tail node.
In the final section of the example, we have a JTC class with a main method. Inside the main method, we create an object of the LinkedList class (LinkedList l1 = new LinkedList()), representing the linked list data structure. We then invoke the create() method five times with different arguments to create new nodes with different data. Finally, we call the print() method to traverse the linked list from the first node to the last node, printing the elements.

Where we use Linked List Data Structure in Application Development?

In application development, there are various situations where the Linked List data structure is the first choice for programmers due to its specific characteristics.

Characteristics of Linked List Data Structure:

a. Dynamic Length: In a Linked List, we use nodes to store elements, and each node has its own memory allocation. This allows the linked list to grow or shrink easily at runtime, making it more flexible in terms of size compared to other data structures like arrays.
b. Efficient Insertion & Deletion Compared to Arrays: In previous tutorials, we have seen how insertion and deletion in arrays can be complex and time-consuming, as it often requires shifting elements. However, in a Linked List, insertion and deletion are more efficient because these operations only involve updating node references, making them faster and simpler than in arrays.

Note:- We will discuss about the Insertion and Deletion operation into the further tutorials.

c. Linked List is a Fundamental Data Structure: The Linked List is a fundamental data structure, meaning it can be used as a foundation to implement other data structures such as Stack and Queue in programming. It provides a straightforward way to implement these structures due to its flexible nature.

Note:- We will discuss the implementation of Stack and Queue data structures in further tutorials.