title: Concatenate string for linked list
body: <p>I am trying to write a method to concatenate a specified string called lstring to the end of this lstring. My problem right now is that my required return type is different from the type I use to perform the recursive function.</p>
  
  <p>This is a linked list class (LString) that calls and references another class (Node). We are to specifically use this method header: <code>public LString concat(LString lstr)</code></p>
  
  <p><em>How do I correct my concatenation method so that I can accept the required LString type?</em></p>
  
  <p>This is the method I tried:</p>
  
  <pre><code>   public LString concat(LString lstr){
        if(front == null){
           return this;
        }
        LString lstr2 = new LString();
        return front.toString() + concat(front.getNext()); 
         }
  </code></pre>
  
  <p>Here is the relevant code for my classes:</p>
  
  <pre><code>    public class LString{
  
         private Node front = null;  //first val in list
         private Node back;   //last val in list
         private int size = 0;
         private int i;
  
         public LString(){
            //construct empty list
            Node LString = new Node();
            front = null;
  
         }
     public String toString(){
        if(front == null){
           return "[]";
        } else {
           String result = "[" + front.data;
           Node current = front.next;
           while(current != null){
              result += current.data; //might need to add ", page 967
              current = current.next;
           }
           result += "]";
           return result;
        }   
     }
  </code></pre>
  
  <p>And my Node class (singly linked nodes):</p>
  
  <pre><code>public class Node{
     public char data;
     public Node next;
  
     //constructors from page 956
     public Node()
     {
        this('\0',null);  //'\0' is null char for java
     }
  
     public Node(char initialData, Node initialNext)
     {
        data = initialData;
        next = initialNext;
     }
  </code></pre>
  
  <p>If I can provide anymore information to help clarify the question let me know.</p>
  
  <p><em>Also from <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#trim()" rel="nofollow">http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#trim()</a>
  Concatenates the specified string to the end of this string.
  If the length of the argument string is 0, then this String object is returned. Otherwise, a new String object is created, representing a character sequence that is the concatenation of the character sequence represented by this String object and the character sequence represented by the argument string.
  Examples:
   "cares".concat("s") returns "caress"
   "to".concat("get").concat("her") returns "together"</em></p>