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