### Linked List Introduction and it's Implementation - The Coding Shala

Home >> Data Structures >> Linked List Introduction and its Implementation

In this post, we will learn what is linked list data structure and will implement a singly linked list in Java.

A linked list is a linear data structure. The linked list is a chain of Nodes that are connected using pointers. One Node contains the data/element and a pointer called next that points to the next node. Unlike arrays, linked list elements are not stored in a contiguous location. There are different types of the linked lists like a singly linked list, doubly linked list, and circular linked list. Here we will cover a singly linked list.

The following are main terms used in a linked list:
• next: pointer to the next node
• node: contains data/value and the next pointer
We can create a linked list of different data types like integer, string, etc.

• The size of linked lists is not fixed. We can add or remove nodes as per our requirements.
• Addition and deletion are easy in the linked list. We can do it in O(1) time.
• Like arrays, random access is not possible in the linked list. We need to traverse the linked list to reach the node.

## Implementation of singly linked list

The following is the structure of a linked list in Java:

```// structure of Node
class Node {
int data;
Node next;

Node (int data) {
this.data = data;
}
}
```

Refer to the below full Java program to create and traverse a linked list:

```// Java program to Implement Singly Linked List
// The Coding Shala

// structure of Node
class Node {
int data;
Node next;

Node (int data) {
this.data = data;
}
}

}
}
}

public class Main {
public static void main(String[] args) {
Node second = new Node(6);
Node third = new Node(7);

// connect nodes
second.next = third;

}
}```

Search: O(n)
Insert: O(1)
Deletion: O(1)

Other Posts You May Like