public List<String> permutation(List<String> list, String target, String ans){
if(target.length() <= 1) {
list.add(ans + target);
} else {
for (int i = 0; i < target.length(); i++) {
permutation(
list,
target.substring(0, i) + target.substring(i + 1),
ans + target.charAt(i));
}
}
return list;
}
Enumeration of all combinations Java
Recommended Posts