打印一个字符串的全部子序列
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/bd25f87fa89a86269534c474ff252496.png#pic_center)
package algorithmbasic.class18;
import java.util.ArrayList;
import java.util.List;
public class PrintAllSubsquences {
public static List<String> subs(String s) {
char[] str = s.toCharArray();
int index = 0;
String path = " ";
List<String> ans = new ArrayList<>();
process(str, index, path, ans);
return ans;
}
public static void process(char[] str, int index, String path, List<String> ans) {
if (index == str.length) {
ans.add(path);
return;
}
process(str, index + 1, path, ans);
process(str, index + 1, path + String.valueOf(str[index]), ans);
}
public static void main(String[] args) {
String test = "123";
List<String> ans1 = subs(test);
for (String str : ans1) {
System.out.println(str);
}
System.out.println("=================");
}
}