public class ABCDpaixu {
public static void main(String[] args) {
String s = "ABC";
List<String> list = list(s, "");
System.out.println(list);
}
//为了输出[ABC, ACB, BAC, BCA, CAB, CBA]
public static List<String> list(String base, String buff){
List<String> result = new ArrayList<>();
if(base.length()<=0) {
result.add(buff);
}
for (int i = 0; i < base.length(); i++) {
//new StringBuilder(base).deleteCharAt(i).toString()删除指定的元素
List<String> temp=list(new StringBuilder(base).deleteCharAt(i).toString(),buff+base.charAt(i));
result.addAll(temp);
}
return result;
}
}