/** * @param args */ public static void main(String[] args) { String data = "helots"; List<List<Character>> result = test(data.toCharArray()); for (List<Character> l : result) { for (Character c : l) { System.out.print(c+", "); } System.out.println(); } } private static List<List<Character>> test(char[] data) { List<List<Character>> result = new ArrayList<List<Character>>(); if (data.length == 1) { List<Character> cl = new ArrayList<Character>(); cl.add(data[0]); result.add(cl); return result; } for (char c : data) { char[] surplusChar = getChar(data, c); List<List<Character>> particaList = test(surplusChar); for (List<Character> d : particaList) { List<Character> currentCharList = new ArrayList<Character>(); currentCharList.add(c); currentCharList.addAll(d); result.add(currentCharList); } } return result; } private static char[] getChar(char[] data, char c) { char[] result = new char[data.length - 1]; int j = 0; for (char dc : data) { if (dc != c) { result[j++] = dc; } } return result; }