title: How can I display all the contents of the LinkedList?
body: <p>Please consider the following code for linkedlist. Basically I've created three nodes in the LinkedList class and trying to display the contents but I'm doing something wrong in the DisplayLinkedList() method. Right now I'm getting my output as follows : </p>
  
  <pre><code>B
  C
  null
  </code></pre>
  
  <p>I wanna display it as follows:
      A
      B
      C </p>
  
  <p>respectively. Could anyone tell me where I'm wrong in the DisplayLinkedList() method ?</p>
  
  <pre><code>package MyPackage;
  
  
  class Node {
  
  String data;
  Node next;
  
  public Node(String data, Node next){
  
      this.data = data;
      this.next = next;
  
  }
  
  public String getData(){
      return data;
  }
  
  public Node getNext(){
  
      return next;
  }
  
  public void setNext(Node n){
      next = n;
  }
  
   public String toString() {
       return this.data;
   }
  
  
  }
  
  // CREATING LINKED LIST BACKWARDS AND APPLYING SOME OPERATIONS ON IT
  
  
  class LinkedList{
  
  Node cNode = new Node("C", null);
  
  Node bNode = new Node("B", cNode);
  
  Node list = new Node("A", bNode);
  
  
  public void DisplayLinkedList(){
  
      Node prev = null;
      Node curr = list;
  
      while(curr != null){
  
          prev = curr;
          curr = curr.getNext();
          System.out.println(curr);
  
      }
  
  
  }
  
  
  
  
  public class LinkedListByME {
  
  
  public static void main(String[] args) {
  
  
      LinkedList ll = new LinkedList();
      ll.DisplayLinkedList();
  
  
  
  }
  
  }
  </code></pre>