Alll subsequences problem

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
while(n>0){
String str = cin.next();
printSS(str,"");
n–;
}

}
public static void printSS(String s,String ans){
   if(s.length() == 0){
	   System.out.println(ans);
      return ;
   }
   char cc  = s.charAt(0);
   String res = s.substring(1);
   printSS(res,ans);
   printSS(res,ans+cc);
}

}===========I have printed all subsequences but how to do it in lexicographical order

hi @AbhishekAhlawat1102
in order to print in lexicographical order you have to add all the sub-sequence into an arrayList and then sort the arrayList.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.