a singly linked list, output includes spaces - Java
<p>So, from console, the input is this. (The app class is working fine, that's not the issue)</p>

<pre><code>J [[1, 2, 3] [4, 5] [6, 7]]
</code></pre>

<p>And the output is this:</p>

<pre><code>[1, 2, 3, , 4, 5, , 6, 7]
</code></pre>

<p>Essentially, it's picking up whitespaces or something. Here's my code:</p>

<pre><code> public static &lt;E&gt; SLList&lt;E&gt; joinAllCopy(List&lt;SLList&lt;E&gt;&gt; lists) {
SLList&lt;E&gt; result = new SLList&lt;E&gt;();

for(int i = 1; i &lt; lists.size(); i++){

    SLList &lt;E&gt; temp = lists.get(i); 
    result = lists.get(0);
    Node&lt;E&gt; curr = temp.first;
    while(curr != null){
    result.addLast(curr.item);
    curr = curr.next;
    }       
}

return result;
}
</code></pre>

<p>What I am doing, is taking in an ArrayList of SinglyLinked lists, and then iterating through them to get each element, and adding them to result. Anyway I can get it from including the whitespaces without altering the given toString method?</p>

<p>All the work needs to be done inside the method, so nothing outside of it needs to be altered. I have been killing myself over it for 24 hours now, can't seem to find a way. D:</p>

<p>EDIT:
I think it's because curr.next points to a null value at the end of iterating a list, and then includes it in the final is. However, this may not be so.</p>

<p>Thanks,
Lachlan</p>
