title: Why am I getting an infinite loop in my printList() method of my linked lists assignment?
body: <p>Here is the code for my printList() method: </p>
  
  <pre><code>public String printList() { 
  
  String list = "";
  Node tempnode = headNode;
  
  while (tempnode != null) {
  
    list = list + tempnode.data + ", ";
    tempnode = tempnode.next;
  
  }
  
  return list;
  }
  </code></pre>
  
  <p>I am calling the method with System.out.println(myList.printList()); in my main.
  When I call the method, the list itself is correct, but the list is printed an infinite amount of times and I can't figure out why. Any help is appreciated!</p>