title: Converting an array into a LinkedList
body: <p>I have an array of characters and I'm trying to convert each character into a node that links to the next node in line. The problem is I keep getting caught in infinite loops and I have no idea why. Here's my code:</p>
  
  <pre><code>String map = "ABBACBCCA";
  char[] charArray = map.toCharArray();
  ListNode head;
  ListNode temp;
  ListNode next;
  
  for (int i = 0; i &lt; charArray.length - 1; i++) {
       temp = new ListNode(charArray[i]);
       next = new ListNode(charArray[i+1]);
       temp.next = next;
  
       if (i == 0) {
            head = temp;
       }
  }
  </code></pre>
  
  <p>And the ListNode class looks like:</p>
  
  <pre><code>class ListNode&lt;T&gt; {
       public T data = null;
       public ListNode next = null;
  
       public ListNode(T data) {
            this.data = data;
       }
  }
  </code></pre>
  
  <p>It looks like it gets to the last iteration of the for loop and then gets caught in an infinite loop.. Anyone know why?</p>