Write a java program to merge three singly linked list elements

Write a java program to merge three singly linked list elements. A Linked List is a collection of nodes, or objects, that are stored in memory at random. To print as a single putput, we can combine or concatenate three singly linked lists. A node has two fields: data stored at that address and a pointer to the memory’s next node. The pointer to null is in the last node of the list.

public class Main
{
Node head;
static class Node
{

int data;
Node next;
Node(int d)
{
data = d;
next=null;

}
}
public void display()
{
Node n = head;
while (n != null)
{
System.out.print(n.data+" \n");
n = n.next;
}
}
public static void main(String[] args)
{
Main Main = new Main();

Main.head = new Node(10);
Node second = new Node(15);
Node third = new Node(20);

Main.head.next = second;
second.next = third;
Main.display();
}
}

10

15

20