private static final String[] KEYS = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; public List<String> letterCombinations(String digits){ List<String> combinations = new ArrayList<>(); if(digits == null || digits.length() == 0){ return combinations; } doCombination(new StringBuilder(),combinations,digits); return combinations; } private void doCombination(StringBuilder prefix,List<String> combinations,final String digits){ if(prefix.length() == digits.length()){ combinations.add(prefix.toString()); return; } int curDisits = digits.charAt(prefix.length()) - '0'; String letters = KEYS[curDisits]; for(char c:letters.toCharArray()){ prefix.append(c); doCombination(prefix, combinations, digits); prefix.deleteCharAt(prefix.length()-1); } }