inserting new node at the beginning of singly linked list note that this method works even if the list is empty note that we set the next pointer for the new node before we make variable head point to inserting an element at the tail of singly linked list we can also easily insert an element at the tail of the listprovided we keep reference to the tail nodeas shown in figure in this casewe create new nodeassign its next reference to point to the null objectset the next reference of the tail to point to this new objectand then assign the tail reference itself to this new node we give the details in code fragment