title: Java linked List implementation won't add data
body: <p>I created my own linked list in java(code below) and I was trying to store DNA?RNA sequences from a text file in an array of a custom data type that contains the enum DNA/RNA, as well as a linked list containing the actual DNA sequence. I don't know if the characters are just not being inserted into the linked list or if there is a problem with my toString but the output only prints the position and enum type, not the sequence from the list. Code is below 
  My node class</p>
  
  <pre><code>public class Node&lt;E&gt; {
      private Node&lt;E&gt; next;
      protected E data;
  
      Node(E data,Node&lt;E&gt; nextVal){
          this.data=data;
          next=nextVal;
      }
      Node(Node&lt;E&gt; nextVal){
          next=nextVal;
      }
  
      Node&lt;E&gt; Next(){
          return next;
      }
      Node&lt;E&gt;setNext(Node&lt;E&gt; nextVal){
          return next=nextVal;
      }
      E data(){
          return data;
      }
      E setData(E it){
          return data=it;
      }
  }
  </code></pre>
  
  <p>My Linked List Class</p>
  
  <pre><code>    public class MyLinkedList&lt;E&gt; implements List&lt;E&gt;{
      private Node&lt;E&gt; head;
      private Node&lt;E&gt; tail;
      protected Node&lt;E&gt; curr;
      private int size;
      MyLinkedList(int size){
          this();
      }
      MyLinkedList(){
          curr=tail=head=new Node&lt;E&gt;(null);
          size=0;
      }
        @Override
        public void clear() {
          head.setNext(null);
          curr=tail=head=new Node&lt;E&gt;(null);
          size=0;
        }
  
        @Override
        public void insert(E item) {
          curr.setNext(new Node&lt;E&gt;(item, curr.Next()));
          if(tail==curr)
              tail=curr.Next();
          size++;
  
        }
        @Override
        public void append(E item) {
          tail=tail.setNext(new Node&lt;E&gt;(item, null));
          size++;
        }
  
        @Override
        public E remove() {
          if(curr.Next() ==null)
            return null;
          E item=curr.Next().data();
          if(tail==curr.Next())
              tail=curr;
          curr.setNext(curr.Next().Next());
          size--;
          return item;
      }
  
        @Override
        public void moveToStart() {
          curr =head;
        }
  
        @Override
        public void moveToEnd() {
          curr=tail;
        }
  
        @Override
        public void prev() {
          if(curr==head)
              return;
          Node&lt;E&gt; temp=head;
          while (temp.Next()!=curr)
              temp=temp.Next();
          curr=temp;
  
        }
  
        @Override
        public void next() {
          if(curr!=tail)
              curr=curr.Next();
        }
  
        @Override
        public int length() {
            return size;
        }
  
        @Override
        public int currPos() {
            Node&lt;E&gt;temp=head;
            int i;
            for(i=0;curr!=temp;i++)
                temp.Next();
            return i;
  
        }
  
        @Override
        public void moveToPos(int pos) {
          assert (pos&gt;=0)&amp;&amp; (pos&lt;=size):
            "Position out of Range";
          curr=head;
          for(int i=0;i&lt;pos;i++)
              curr.Next();
  
        }
  
        @Override
        public E getValue() {
            if(curr.Next()==null)
                return null;
            return curr.Next().data();
        }
  
        @Override
       public String toString() {
            String result = "";
            Node current = head;
            while(current.Next() != null){
                result += current.data();
                if(current.Next() != null){
                    result += ", ";
                }
                current = current.Next();
            }
            return "" + result;
        }
  }
  </code></pre>
  
  <p>This is the SequenceArr class which handles the operations on the array mentioned above (not complete here but all that is used in this example)</p>
  
  <pre><code> public class SequenceArr {
   private TypeSeq [] SeqArr;
   private int size=0;
   private int MAXSIZE;
  
   public SequenceArr(int MAXSIZE){
       this.MAXSIZE=MAXSIZE;
       SeqArr =new TypeSeq[MAXSIZE];
       size=0;
   }
   public void insert(int pos, Type t, MyLinkedList&lt;Character&gt; seq){
       TypeSeq currentEl=new TypeSeq(t,seq);
       assert pos&lt;=MAXSIZE: "Position over maximum size of array";
       SeqArr[size]=currentEl;
       size++;
      }
   public void remove(int pos){
       if(SeqArr[pos]!=null){
           while(SeqArr[pos+1]!=null){
               SeqArr[pos]=SeqArr[pos+1];
           }
           if(SeqArr[pos+1]==null){
               SeqArr[pos]=null;
           }
        }
       else
           System.out.print("No sequence to remove at specified position");
      }
   public void print(){
       int i=0;
       while (SeqArr[i]!=null){
           System.out.println(i+"\t"+SeqArr[i].getType()+"\t"+SeqArr[i].getBioSeq().toString());
           i++;
       }
      }
   public void print(int pos){
          if(SeqArr[pos]==null)
              System.out.print("No sequence to print at specified position");
          else
              System.out.println(SeqArr[pos].getType()+"\t"+SeqArr[pos].getBioSeq().toString());
      }
  </code></pre>
  
  <p>The custom data type i created that the array is made of</p>
  
  <pre><code>public class TypeSeq {
      private Type type;
      private MyLinkedList&lt;Character&gt; BioSeq;
      public TypeSeq(Type type, MyLinkedList&lt;Character&gt; BioSeq){
          this.type=type;
          this.BioSeq=BioSeq;
      }
  
      public MyLinkedList&lt;Character&gt; getBioSeq() {
          return BioSeq;
      }
  
      public void setBioSeq(MyLinkedList&lt;Character&gt; bioSeq) {
          BioSeq = bioSeq;
      }
  
      public Type getType() {
          return type;
      }
  
      public void setType(Type type) {
          this.type = type;
      }
  }
  </code></pre>
  
  <p>and my DNAList class which handles input and contains the main method</p>
  
  <pre><code>    import java.io.File;
  import java.io.FileNotFoundException;
  import java.util.Scanner;
  
  public class DNAList {
      static SequenceArr seqar;
      public static void main(String []args){
          MyLinkedList&lt;String&gt; hey=new MyLinkedList&lt;&gt;();
          hey.append("Hello");
  
          int arraysize= Integer.parseInt(args[0]);
          String filePath=args[1];
          File file=new File(filePath);
          seqar=new SequenceArr(arraysize);
          exefromFile(file);
  
      }
  
      public static void exefromFile(File file){
          Scanner sc;
          try{
              sc=new Scanner(file);
              while(sc.hasNextLine()){
                  String cmd=sc.nextLine();
                  if(!cmd.equals(""))
                      execute(cmd);
              }
  
  
          }catch (FileNotFoundException e){
              e.printStackTrace();
  
          }
      }
  
      public static void execute(String s){
          s=s.trim();
          String [] commands=s.split("\\s+");
          switch (commands[0])
          {
              case "insert":
                  int pos=Integer.parseInt(commands[1]);
                  Type t=Type.fromString(commands[2]);
                  char [] charArr=commands[3].toCharArray();
                  MyLinkedList&lt;Character&gt; seq=new MyLinkedList&lt;&gt;(charArr.length);
                  char curChar;
                  for(int i=0;i&lt;seq.length();i++){
                      curChar=charArr[i];
                      if(t==Type.DNA&amp;&amp;(curChar=='A'||curChar=='C'||curChar=='G'||curChar=='T'))
                          seq.append(charArr[i]);
                      else
                          System.out.print("Error occurred while inserting");
                  }
                  seqar.insert(pos,t,seq);
                  break;
              case "remove":
                  pos=Integer.parseInt(commands[1]);
                  seqar.remove(pos);
                  break;
              case "print":
                  if(commands.length&gt;1&amp;&amp;commands[1]!=null){
                      pos=Integer.parseInt(commands[1]);
                      seqar.print(pos);
                  }
                  else
                      seqar.print();
                  break;
              case "clip":
                  pos=Integer.parseInt(commands[1]);
                  int start =Integer.parseInt(commands[2]);
                  int end =Integer.parseInt(commands[3]);
                  seqar.clip(pos,start,end);
                  break;
              case "copy":
                  int pos1=Integer.parseInt(commands[1]);
                  int pos2=Integer.parseInt(commands[2]);
                  seqar.copy(pos1,pos2);
                  break;
              case "transcribe":
                  pos=Integer.parseInt(commands[1]);
                  seqar.transcribe(pos);
                  break;
          }
  
      }
  
  }
  </code></pre>
  
  <p>The input .txt file will say something like</p>
  
  <p>insert 0 DNA AATTCCGGAATTCCGG</p>
  
  <p>print</p>
  
  <p>but the output will just be </p>
  
  <p>0   DNA
  and the sequence will not be printed. Any ideas?</p>