# Linked List fundamental concepts [closed]

I am trying to understand the basics of Linked List. The definition of my LinkedList class is as follows:

public class ListNode {
int val;
ListNode next;
ListNode(int x) { val = x; }


Now I am facing a problem. My code is as follows:

ListNode dummy = new ListNode(0);
ListNode prev = dummy;
prev.next = slow;

ListNode temp = slow.next;
prev.next = temp;

System.out.println(dummy.next); //comes out null


Why is it coming out as null? dummy.next was pointing to head and I only changed slow and prev?

Can we use slow and head interchangeably? If yes, then why does this happen?

// head points to a Linked list starting from 1 in 1 -> 2 -> 3

while(curr.next!= null){
curr= curr.next;
}

System.out.println(curr);


## closed as off-topic by Yuval Filmus, Discrete lizard♦, Evil, David Richerby, vonbrandJul 6 '18 at 15:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "Questions about software development or programming tools are off-topic here, but can be asked on Stack Overflow." – Yuval Filmus, Discrete lizard, Evil, David Richerby, vonbrand
If this question can be reworded to fit the rules in the help center, please edit the question.

• Hi! Thanks for answering. So, both dummy and prev point to the same object. But what confuses me is that what different am I doing in both the code snippets that causes this difference? Am I reassigning curr to a different object in the second and changing the pointer of prev and thus dummy in the first? Am I correct in understanding this? – crazyy_photonn Jun 30 '18 at 2:30