package com.example; public class Node { private int data; private Node next; public Node(int data) { this.data = data; this.next = null; } public int getData() { return data; } public Node getNext() { return next; } public void setNext(Node next) { this.next = next; } }
Node head = new Node(1); Node second = new Node(2); Node third = new Node(3); head.setNext(second); second.setNext(third);This creates a linked list with three nodes, with the first node having a data value of 1, the second node having a data value of 2, and the third node having a data value of 3. The next references for each node are set accordingly, creating a linked list structure. The Node class is typically included in the java.util package library.