Schuyler Bradshaw
Schuyler Bradshaw

Reputation: 9

How does assigning Nodes to other Nodes work when creating methods like two string in a Java LinkedList

When you assign the front Node of the linked list to a copy Node I understand that you are assigning Node f the same address as front. This means that when you say f = f.next why doesn't it change the original Node front. I wounder this becuase Object = Object means they reference the same Object.

    public String toString(){
        StringBuilder string = new StringBuilder();
        Node<E> f = front;
        while(f != null){
            string.append(f.item).append(" ");
            f = f.next;
        }
        return string.toString();
    }

This code works but I am wondering why?

Upvotes: 0

Views: 16

Answers (0)

Related Questions