Linked list is a most important data structure of the java. One of the most basic thing from this data structure is to print the elements .
Input : 1 -> 2 -> 3 -> 4 -> null
Output : 1 2 3 4
Input : 1 -> null
Output : 1
Input : null
Output : null
Output : 1 2 3 4
Input : 1 -> null
Output : 1
Input : null
Output : null
Java Code :