LinkedLists, building a toString method for custom linked list class <p>I'm struggling with completing this <code>toString()</code> method within my linked list class called <code>LString</code></p> <p>The class creates an LString object that mimics String and StringBuilder with a linked list rather than an array. It creates strings out of linked lists.</p> <p>Here is the code for the method:</p> <pre><code>public String toString(){ StringBuilder result = new StringBuilder(); node curr = front; while (curr != null){ result.append(curr.data); curr = curr.next; } return result.toString(); } </code></pre> <p>I have tried several different things, and I think I'm close to figuring it out. But I can't move forward from this error message:</p> <pre><code>Running constructor, length, toString tests (10 tests) Starting tests: .......E.E Time: 0.009 There were 2 failures: 1) t11aLStringOfStringToString[1](LStringTest$LStringOfStringTest) org.junit.ComparisonFailure: LString("ab").toString() is wrong. expected:&lt;[a]b&gt; but was:&lt;[]b&gt; at org.junit.Assert.assertEquals(Assert.java:115) at LStringTest$LStringOfStringTest.t11aLStringOfStringToString(LStringTest.java:221) ... 10 more 2) t11aLStringOfStringToString[2](LStringTest$LStringOfStringTest) org.junit.ComparisonFailure: LString("This is a long string.").toString() is wrong. expected:&lt;[This is a long string].&gt; but was:&lt;[].&gt; at org.junit.Assert.assertEquals(Assert.java:115) at LStringTest$LStringOfStringTest.t11aLStringOfStringToString(LStringTest.java:221) ... 10 more Test Failed! (2 of 10 tests failed.) Test failures: abandoning other phases. </code></pre> <p>The <code>LString</code> class uses another class, LStringTest.java to do various tests. This error message is from running LStringTest.java, but the method that I'm working on is within LString. It is the, <code>LString("ab").toString() is wrong</code> bit.</p> <p>For some context, here is the rest of my class:</p> <pre><code>public class LString { // 2. Fields node front; //node tail; int size; // 1. Node class private class node { char data; node next; //constructors //1. default public node (){ } //2. data public node (char newData){ this.data = newData; } //3. data + next public node (char newData, node newNext){ this.data = newData; this.next = newNext; } } // 3. Constructors public LString(){ this.size = 0; this.front = null; } public LString(String original) { for (int i =0; i &lt; original.length(); i++) { this.front = new node(original.charAt(i)); } this.size = original.length(); } // 4. Methods public int length() { return this.size; } public int compareTo(LString anotherLString) { return 0; } public boolean equals(Object other) { if (other == null || !(other instanceof LString)) { return false; } else { LString otherLString = (LString)other; return true; } } public char charAt(int index) { return 'a'; } public void setCharAt(int index, char ch) { ch = 'a'; } public LString substring(int start, int end) { return null; } public LString replace(int start, int end, LString lStr) { return null; } //append public void append(char data){ this.size++; if (front == null){ front = new node(data); return; } node curr = front; while (curr.next != null){ curr = curr.next; } curr.next = new node(data); } //prepend public void prepend (char data){ /*node temp = new node(data); temp.next = front; front = temp;*/ front = new node(data, front); size++; } //delete public void delete(int index){ //assume that index is valid if (index == 0){ front = front.next; } else { node curr = front; for (int i = 0; i &lt; index - 1; i++){ curr = curr.next; } curr.next = curr.next.next; } size--; } //toString public String toString(){ StringBuilder result = new StringBuilder(); //result.append('['); node curr = front; while (curr != null){ //result.append('['); result.append(curr.data); curr = curr.next; //result.append(']'); //if (curr.next != null){ //} } //result.append(']'); return result.toString(); } //add (at an index) public void add(int index, char data){ if (index == 0){ front = new node(data, front); } else { node curr = front; for (int i = 0; i &lt; index - 1; i++){ curr = curr.next; } curr.next = new node(data, curr.next); } } } </code></pre>