title: How to print LinkedList Node object in reverse order
body: <p>In the following method <code>reverse()</code> ,I wanted to access the elements of <code>Node</code> and add them in an <code>ArrayList</code>.After that ,using loop, it will print in reverse order.</p>
  
  <pre><code>public void reverse(){
  
              Node e = head;
              ArrayList&lt;E&gt; s = new ArrayList&lt;E&gt;();
              while(e!=null){
  
                  s.add(e.element);
                  e= e.next;
              }
              for (int i = count-1; i &gt;= 0; i--) {
                  System.out.print (""+s.get(i));
              }
              System.out.println("");
  
      }
  </code></pre>
  
  <p>But, <code>s.add(e.element) ;</code> is giving an error.
  Here is Node class,</p>
  
  <pre><code>public class Node&lt;E&gt; {
      E element;
      Node&lt;E&gt; next;
  
      public Node(E element){
          this.element=element;
          next =null;
      }
  }
  </code></pre>
  
  <p>and LinkedList class</p>
  
  <pre><code>     public class LinkedListStack&lt;E&gt; implements Stack&lt;E&gt;{
              Node&lt;E&gt; head;
              Node&lt;E&gt; tail;
              int count=-1;
  
              public LinkedListStack() {
                 head=tail=null;
              }
  
       public void push(E element) {
              Node&lt;E&gt; newNode = new Node&lt;&gt;(element);
              if(count==-1){
                  head=tail=newNode;
                  count++;
              }
              else{
                  newNode.next=head;
                  head = newNode;
              }
              count++;
          }
               public void reverse(){
  
                  Node e = head;
                  ArrayList&lt;E&gt; s = new ArrayList&lt;E&gt;();
                  while(e!=null){
  
                      s.add(e.element);
                      e= e.next;
                  }
                  for (int i = count-1; i &gt; 1; i--) {
                      System.out.print (""+s.get(i));
                  }
                  System.out.println("");
  
              }
  }
  </code></pre>
  
  <p>I will appreciate if someone explains the the error for adding Object</p>
  
  <p>element in the ArrayList in details.</p>