title: What is wrong with the set method of my LinkedList
body: <p>Im trying to implement a linkedlist.. All of my methods work except for the set method. It is only supposed to change the replace the element at the given index. But after setting the element in the index it is making the rest of the elements in the list to null, can anyone point out what I'm doing wrong in the set method?</p>
  
  <pre><code>        public class LArrayList&lt;E&gt; {
  
              private static class Node&lt;E&gt; {
  
                  Node&lt;E&gt; next;
  
                  E data;
  
                  public Node(E dataValue) {
                      next = null;
                      data = dataValue;
                  }
  
                  @SuppressWarnings("unused")
                  public Node(E dataValue, Node&lt;E&gt; nextValue) {
                      next = nextValue;
                      data = dataValue;
                  }
  
                  public E getData() {
                      return data;
                  }
  
                  public Node&lt;E&gt; getNext() {
                      return next;
                  }
  
                  public void setNext(Node&lt;E&gt; nextValue) {
                      next = nextValue;
                  }
              }
  
              private Node&lt;E&gt; head;
              private static int listCount;
  
              public LArrayList() {
  
                  head = new Node&lt;&gt;(null);
                  listCount = 0;
              }
  
              public void add(int index, E e) throws IndexOutOfBoundsException{
  
                  if (index &lt; 0 || index &gt;= listCount + 1) {
  
                      throw new IndexOutOfBoundsException("Bad index, please use index within range");
                  }
                  else{
  
  
                  Node&lt;E&gt; positionTemp = new Node&lt;&gt;(e);
                  Node&lt;E&gt; positionCurrent = head;
  
                  for (int i = 0; i &lt; index &amp;&amp; positionCurrent.getNext() != null; i++) {
                      positionCurrent = positionCurrent.getNext();
                  }
  
                  positionTemp.setNext(positionCurrent.getNext());
                  positionCurrent.setNext(positionTemp);
                  listCount++;
              }
              }
  
              public E set(int index, E e) throws IndexOutOfBoundsException {
  
                  if (index &lt; 0 || index &gt;= listCount) 
                      throw new IndexOutOfBoundsException("Bad index, please use index within range");
  
  
                  Node&lt;E&gt; positionTemp = new Node&lt;&gt;(e);
                  Node&lt;E&gt; positionCurrent = head;
  
                  for (int i = 0; i &lt; index; i++) {
                      positionCurrent = positionCurrent.getNext();
                  }
  
  
                  positionCurrent.setNext(positionTemp);
  
                  return positionCurrent.getData();
  
              }
  
      public E get(int index) throws IndexOutOfBoundsException
      {
  
          if (index &lt; 0 || index &gt;= listCount)
              throw new IndexOutOfBoundsException("Bad index, please use index within range");
  
          Node&lt;E&gt; positionCurrent = head.getNext();
          for (int i = 0; i &lt; index; i++) {
              if (positionCurrent.getNext() == null)
                  return null;
  
              positionCurrent = positionCurrent.getNext();
          }
          return positionCurrent.getData();
      }
  
  
  
              public static void main(String[] args) {
  
                  LArrayList&lt;String&gt; aa = new LArrayList&lt;String&gt;();
                  aa.add(0, "0");
                  aa.add(1, "1");
                  aa.add(2, "2");
                  aa.add(3, "3");
                  aa.add(4, "4");
                  aa.add(5, "5");
  
  
                  System.out.println("The contents of AA are: " + aa);    
  
                   aa.set(0, "a");
  
  
                  System.out.println("The contents of AA are: " + aa);    
  
  
  
                   System.out.println(aa.get(0));
  
                   System.out.println(aa.get(1));
  
                   System.out.println(aa.get(2));
                   System.out.println(aa.get(3));
  
                   System.out.println(aa.get(4));
  
                   System.out.println(aa.get(5));
  
          //OUTPUT IS: The contents of aa are: [0][1][2][3][4][5]
          //The contents of AA are: [a][b][c][d][e]
          //a
          //A
          //null
          //null
          //null
          //null
  
              }
  
          }
  </code></pre>