title: How to duplicate every element of a linked list recursively in Java?
body: <p>I have to write a duplicate function that duplicates every element of a linked list and returns a linked list such that if L = [2,3,4] then duplicate(L) = [2,2,3,3,4,4]. I have to do this recursively. I realize that below is not the correct solution, but I got confused. =(</p>
  
  <pre><code>   public class MyList {
       int value;
       MyList next;
  
       public static MyList duplicate(MyList L){
          if(L.next == null){
             L.next.value = L.value;
             L.next.next = null;
          } else {
             MyList temp = L.next;
             L.next.value = L.value;
             L.next.next = temp;
             duplicate(L.next);
          }
          return L;
      }
  }
  </code></pre>