title: LZW decoding miss the first code entry
body: <p>I followed the  <a href="http://rosettacode.org/wiki/LZW_compression#Java" rel="nofollow">Rosetta Java code</a> implementation.</p>
  
  <p>I tried do this LZW coding with my own Dictionary and not with the ASCII Dictionary which was used.
  When I try with my own Dictioanry there is a problem about decoding... The result is wrong, because each of decoded word don't view the first <code>'a'</code> letter.
  The result have to be <code>'abraca abrac abra'</code> and not <code>'braca brac bra'</code></p>
  
  <p>I see the problem in decode() method at <code>String act = "" + (char)(int)compressed.remove(0);</code> This will remove all first 'a' letter.
  But I don't have any ideas how can I modify this line... 
  For example if I use the <code>String act = "";</code>instead of above line... the coding will be very wrong, or use another command... I don't know how can I solve this little problem... Or maybe I am looking for on the bad way for the solution.</p>
  
  <pre><code>public class LZW {  
  
  
  public static List&lt;Integer&gt; encode(String uncompressed) {
  
      Map&lt;String,Integer&gt; dictionary = DictionaryInitStringInt();        
      int dictSize = dictionary.size();
  
      String act = "";
      List&lt;Integer&gt; result = new ArrayList&lt;Integer&gt;();
  
      for (char c : uncompressed.toCharArray()) {
          String next = act + c;
          if (dictionary.containsKey(next))
              act = next;
          else {
              result.add(dictionary.get(act));
              // Add next to the dictionary.
              dictionary.put(next, dictSize++);
              act = "" + c;
          }
      }
  
      // Output the code for act.
      if (!act.equals(""))
          result.add(dictionary.get(act));
      return result;
  } 
  
  public static String decode(List&lt;Integer&gt; compressed) {
  
      Map&lt;Integer,String&gt; dictionary = DictionaryInitIntString();        
      int dictSize = dictionary.size();
  
      String act = "" + (char)(int)compressed.remove(0);
      //String act = "";
      String result = act;
  
      for (int k : compressed) {            
          String entry;
          if (dictionary.containsKey(k))
              entry = dictionary.get(k);
          else if (k == dictSize)
              entry = act + act.charAt(0);
          else
              throw new IllegalArgumentException("Nincs ilyen kulcs: " + k);
  
          result += entry;
  
          dictionary.put(dictSize++, act + entry.charAt(0));
  
          act = entry;
      }
      return result;
  }
  
  public static Map&lt;String,Integer&gt; DictionaryInitStringInt()
  {               
      char[] characters = {'a','b','c','d','e','f','g','h','i','j', 'k','l','m','n',
                      'o','p','q','r','s','t','u','v','w','x','y','z',' ','!',
                      '?','.',','};
      int charactersLength = characters.length;
  
      Map&lt;String,Integer&gt; dictionary = new HashMap&lt;String,Integer&gt;();
  
      for (int i = 0; i &lt; charactersLength; i++)
              dictionary.put("" + characters[i], i); 
  
      return dictionary;
  }
  
  public static Map&lt;Integer,String&gt; DictionaryInitIntString()
  {               
      char[] characters = {'a','b','c','d','e','f','g','h','i','j', 'k','l','m','n',
                      'o','p','q','r','s','t','u','v','w','x','y','z',' ','!',
                      '?','.',','};
      int charactersLength = characters.length;
  
      Map&lt;Integer,String&gt; dictionary = new HashMap&lt;Integer,String&gt;();
  
      for (int i = 0; i &lt; charactersLength; i++)
              dictionary.put(i,"" + characters[i]); 
  
      return dictionary;
  }
  
  public static void main(String[] args) {
  
      List&lt;Integer&gt; compressed = encode("abraca abrac abra");
      System.out.println(compressed);
  
      String decodeed = decode(compressed);
      // decodeed will be 'braca brac bra'
      System.out.println(decodeed);
  }
  </code></pre>
  
  <p>}</p>