title: Convert Linkedlist to ArrayList
body: <p>I had to write a program to do LZWDecode and I decided to use LinkedList to write the  LZWDecode program below  but I want to convert it to an ArrayList. Anyone have idea on how I can convert the LinkedList to an ArrayList to make it simpler.
  Thanks.</p>
  
  <pre><code>import java.util.*;
  
  public class LZWDecoder {
  
  private final int CLEAR_TABLE=256;
  private final int END_OF_DATA=257;
  private final int TABLE_SIZE=4096;
  
  private static LinkedList&lt;Integer&gt; input = new LinkedList&lt;Integer&gt;();
  @SuppressWarnings("unchecked")
  private LinkedList&lt;Integer&gt;[] table
          = new LinkedList[TABLE_SIZE];
  private LinkedList&lt;Integer&gt; temp = new LinkedList&lt;Integer&gt;();
  private int index = 258;
  private LinkedList&lt;String&gt; trace = new LinkedList&lt;String&gt;();
  private boolean view = true;
  
  private void enterData() {
  Scanner scan = new Scanner(System.in);
  System.out.println("Please enter the Input Code (EOD = 257):");
  int n=0;
  while(n!=END_OF_DATA &amp;&amp; scan.hasNextInt()){
  n = scan.nextInt();
  //System.out.println("Adding "+n);
  input.add(n);
  }
  
  System.out.println("Decoding...\nOutput:");
  String code="";
  for(int i=0; i&lt;input.size(); i++) {
  code+=input.get(i)+" ";
  }
  trace.add("\nInput: "+code);
  //test
  /*
  while(!input.isEmpty()) {
  System.out.println(input.remove());
  }
  */
  }
  
  private void reset() {
  trace.add("Clearing...");
  //table.clear();
  for(int i=0; i&lt;TABLE_SIZE;i++) {
  table[i] = new LinkedList&lt;Integer&gt;();
  }
  }
  
  private void decode(int c) {
  switch(c) {
  case CLEAR_TABLE:
  trace.add("decode\t"+CLEAR_TABLE+"-&gt;[256]");
  reset();
  break;
  case END_OF_DATA:
  trace.add("decode\t"+END_OF_DATA+"-&gt;[257]");
  trace.add("Decoding finished.");
  break;
  default:
  if(c&lt;256) {
  trace.add("decode\t"+c+"-&gt;["+c+"]");
  if(!temp.isEmpty()) append(c);
  emit(c);
  add(temp);
  } else {
  trace.add("decode\t"+c+"-&gt;["+printTableNode(table[c])+"]");
  if(!temp.isEmpty()) append(table[c].get(0));
  emit(c, table[c]);
  add(temp);
  }
  }
  }
  
  private void emit(int n, LinkedList&lt;Integer&gt; c) {
  //int [] a=new int[c.size()];
  temp=new LinkedList&lt;Integer&gt;();
  for(int i=0; i&lt;c.size(); i++) {
  //a[i]=c.get(i);
  System.out.print(c.get(i)+" ");
  temp.add(c.get(i));
  }
  trace.add("emit\t"+n+"-&gt;"+"["+printTableNode(c)+"]");
  
  }
  
  private void emit(int c) {
  //print out output
  temp=new LinkedList&lt;Integer&gt;();
  temp.add(c);
  trace.add("emit\t"+c+"-&gt;"+"["+c+"]");
  System.out.print(c+" ");
  }
  
  /*
  private void add(int c) {
  //added to table is copied to temp
  table[index].add(c);
  temp = (LinkedList)table[index].clone();
  trace.add("add\t"+index+"-&gt;["+printTableNode(table[index])+"]");
  }
  */
  
  private void add(LinkedList&lt;Integer&gt; c) {
  for(int i=0; i&lt;c.size();i++) {
  //temp.add(c.get(i));
  table[index].add(c.get(i));
  }
  trace.add("add\t"+index+"-&gt;["+printTableNode(table[index])+"]");
  }
  
  
  private void append(int c) {
  //table[c].add(12);//add what?
  //temp.add(c);
  table[index].add(c);
  trace.add("append\t"+index+"-&gt;["+printTableNode(table[index])+"]");
  index++;
  }
  
  private String printTableNode(LinkedList l) {
  String list="";
  for(int i=0; i&lt;l.size();i++) {
  list+=l.get(i);
  if(i&lt;l.size()-1) {
  list+=", ";
  }
  }
      return list;
  }
  
  private void printTrace() {
  System.out.print("Printing Trace...");
  for(int i=0; i&lt;trace.size(); i++) {
  System.out.println(trace.get(i));
  }
  }
  
  public static void main(String[] args) {
  // TODO code application logic here
  LZWDecoder d = new LZWDecoder();
  d.enterData();
  while(!input.isEmpty()) {
  d.decode(input.remove());
  }
  System.out.print("\n\n");
  d.printTrace();
  }
  
  }
  </code></pre>