Java tutorial
//package com.java2s; import java.util.HashMap; public class Main { public static String decodeLZW(int[] encodedText, HashMap<Integer, String> dict, int dictSize) { String decodedText = ""; for (int i = 0; i < encodedText.length; i++) { String nextString = ""; String currentEntry = dict.get(encodedText[i]); decodedText = decodedText.concat(currentEntry); if (i + 1 < encodedText.length && dict.size() < dictSize) { if (encodedText[i + 1] < dict.size()) nextString = dict.get(encodedText[i + 1]); else nextString = currentEntry; String nextChar = String.valueOf(nextString.charAt(0)); if (!dict.containsValue(currentEntry.concat(nextChar))) { dict.put(dict.size(), currentEntry.concat(nextChar)); } } } return decodedText; } }