0 votes
44 views
in Data Structure And Algorithm by (2.8k points)
How to print a linked list in java ?

1 Answer

0 votes
by (2.8k points)
Print all nodes of linked list. See the following code to print linked list:-

public class Node {

int data;

Node next = null;

public Node(int data) {

this.data = data;

}

}

public void print(Node head) {

while(head != null) {

System.out.print(head.data + " ");

head = head.next;

}

}

Output:-

Print LinkedList Data:-

10 5 20

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...